Welcome to Dream.In.Code
Become an Expert!

Join 149,495 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,350 people online right now. Registration is fast and FREE... Join Now!




Storing images in ms access

 
Reply to this topicStart new topic

Storing images in ms access

rajeev_kumar_chopra
6 Mar, 2007 - 10:39 PM
Post #1

New D.I.C Head
*

Joined: 6 Mar, 2007
Posts: 2


My Contributions
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();
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 06:03PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month