saving a file to database

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 11
Reputation: nverma is an unknown quantity at this point 
Solved Threads: 2
nverma nverma is offline Offline
Newbie Poster

saving a file to database

 
0
  #1
Jul 25th, 2009
i need code for saving a file in access database using C#
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 1,941
Reputation: ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of ddanbe has much to be proud of 
Solved Threads: 279
ddanbe's Avatar
ddanbe ddanbe is offline Offline
Posting Virtuoso

Re: saving a file to database

 
0
  #2
Jul 25th, 2009
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.
Last edited by ddanbe; Jul 25th, 2009 at 8:29 am.
Today is a gift, that's why it is called "The Present".
Make love, no war. Cave ab homine unius libri.
Danny
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 11
Reputation: nverma is an unknown quantity at this point 
Solved Threads: 2
nverma nverma is offline Offline
Newbie Poster

Re: saving a file to database

 
0
  #3
Jul 25th, 2009
Originally Posted by ddanbe View Post
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();
Last edited by nverma; Jul 25th, 2009 at 8:41 am.
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 2,612
Reputation: adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of adatapost has much to be proud of 
Solved Threads: 468
Moderator
adatapost's Avatar
adatapost adatapost is offline Offline
Posting Maven

Re: saving a file to database

 
0
  #4
Jul 25th, 2009
Use parameterized query. fcontent field type must be binary (blob/image) ole or something with access db.
  1. string con = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:/C1/App_Data/db4.mdb;Persist Security Info=False";
  2. string q="insert into table(fname,fcontent) values(?,?)"
  3. ...
Failure is not fatal, but failure to change might be. - John Wooden
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC