i need code for saving a file in access database using C#

Recommended Answers

All 3 Replies

Welcome nverma.
What do you mean by saving a file in a database?
Show us the code you already have. And if you do so PLEASE use code tags.

Welcome nverma.
What do you mean by saving a file in a database?
Show us the code you already have. And if you do so PLEASE use code tags.

i have used a FileUpload control to allow user to upload a file (a word document or an excel sheet) and saving this file to my ms access data base.On submit button i'm using the following code:

string con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/C1/App_Data/db4.mdb;Persist Security Info=False";

string q="insert into table(fname,fcontent) values('"+this.FileUpload.Text+"','"+this.FileUpload.Content+"');

OleDbConnection cn = new OleDbConnection(con);
cn.Open();
OleDbCommand cmd = new OleDbCommand(q, cn);
cmd.ExecuteNonQuery();
cn.Close();

Use parameterized query. fcontent field type must be binary (blob/image) ole or something with access db.

string con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/C1/App_Data/db4.mdb;Persist Security Info=False";
string q="insert into table(fname,fcontent) values(?,?)"
...
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.