0 Replies - 3125 Views - Last Post: 06 March 2007 - 11:39 PM Rate Topic: -----

#1 rajeev_kumar_chopra  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 06-March 07

Storing images in ms access

Posted 06 March 2007 - 11:39 PM

I want to upload an image file and store it in ms access database.
Iam using file upload control "File1" to upload the file and streamReader class to read it in string format and store it memo field in access file.
My problem is that while i try to store that string(string in which image file is read) in database
my program does not find the end of string and shows error message invalid sql.

I am using following coding

string fname=Path.GetFileName(File1.PostedFile.FileName);
File1.PostedFile.SaveAs("c:\\uploads\\"+fname);

StreamReader sr=new StreamReader(File.OpenRead("c:\\uploads\\"+fname));
string str=sr.ReadToEnd();

string path="C:\\uploads\\" + fname;
cmd=new OleDbCommand("insert into lib values (name,path,image) values(@a,@b,@c)",conn);

cmd.Parameters.Add("@a",fname);
cmd.Parameters.Add("@b",path);
cmd.Parameters.Add("@c",System.Convert.ToString(str));

conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
sr.Close();

Is This A Good Question/Topic? 0
  • +

Page 1 of 1