Improper syntax.
String query = @"Insert INTO ImagesStore (OriginalPath,ImageDarta) Values ('" + txtImagePath.Text + "','" + pictureBox1.ImageLocation + "')";
__avd
Posting Genius (adatapost)
8,737 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 51
>i want the path and the file to be stored in the database
Firstly, your table column type must be Image to store binary data (file content).
Secondly, you need to write parametrized query.
SqlConnection cn=new SqlConnection("put_conn_str");
String query = @"INSERT INTO ImagesStore (OriginalPath,ImageDarta) Values (@path,@data)";
SqlCommand cmd=new SqlCommand(query,cn);
//read file
byte []barray=System.IO.File.ReadAllBytes(dlg.FileName);
//extract the filename only from the selected path
string filename=System.IO.Path.GetFileName(dlg.FileName);
// create sql parameters
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();
__avd
Posting Genius (adatapost)
8,737 posts since Oct 2008
Reputation Points: 2,141
Solved Threads: 1,262
Skill Endorsements: 51