|
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();
|