Here is the code to insert binary data into DB :
SqlConnection cn=new SqlConnection("put_conn_str");
String query = @"INSERT INTO ImagesStore (OriginalPath,ImageDarta) Values (@path,@data)";
SqlCommand cmd=new SqlCommand(query,cn);
byte []barray=System.IO.File.ReadAllBytes(dlg.FileName);
string filename=System.IO.Path.GetFileName(dlg.FileName);
cmd.Parameters.Add("@path",SqlDbType.VarChar,100).Value=filename;
cmd.Parameters.Add("@data",SqlDbType.Image,barray.Length).Value=barray;
cn.Open();
cmd.ExecuteNonQuery();
cn.Close();
Extracted from here :
http://www.daniweb.com/software-development/csharp/threads/276483[
^]
Of course "path" is
varchar(100)
and "data" is
image
data type.
Also you may use
varbinary
for storing binary data.
"please send me the code to upload a bulk of files"
If you repeat this operation for multiple files you will insert multiple files into the DB.
Hope it helps.