Click here to Skip to main content
15,895,803 members
Please Sign up or sign in to vote.
5.00/5 (1 vote)
See more:
C#
private void button1_Click(object sender, EventArgs e)
{
   try
   {
      OpenFileDialog dlg = new OpenFileDialog();
      dlg.Filter = "JPG Files (*.jpg|*.jpgg|GIF Files (*.gif)|*,gif|All Files (*.*)|*.*";
      dlg.Title = " Select Animal Image ";
      if (dlg.ShowDialog() == DialogResult.OK)
      {
         img = dlg.FileName.ToString();
         pictureBox1.ImageLocation = img;
      }
   }
   catch (Exception ex)
   {
      MessageBox.Show(ex.Message);
   }
}

private void button2_Click(object sender, EventArgs e)
{
   byte[] imgdata = readimage(img);
   SqlConnection obj = new SqlConnection();
   obj.ConnectionString = "Data Source=KHATRII;Initial Catalog=varun;Integrated Security=True";
   obj.Open();
   SqlCommand cmd = new SqlCommand("insert into Table2 values(@idd,@imge", obj);
   cmd.Parameters.Add("@id", SqlDbType.NVarChar, 50).Value = (textBox1.Text);
   cmd.Parameters.Add("@imge", imgdata);
   cmd.ExecuteNonQuery();
}

private byte[] readimage(string img)
{
   byte[] imagedata = null;
   FileInfo fs = new FileInfo(img);
   long length = fs.Length;
   FileStream files = new FileStream(img, FileMode.Open, FileAccess.Read);
   BinaryReader br = new BinaryReader(files);
   imagedata = br.ReadBytes((int)length);
   return imagedata;
}
Posted
Updated 1-Sep-13 1:40am
v2

1 solution

Your query is not well formatted, missing closing ')'
In the following line:
C#
// Add closing tag after '@imge'
SqlCommand cmd = new SqlCommand("insert into Table2 values(@idd,@imge", obj);


Cheers,
Edo
 
Share this answer
 
v3
Comments
ridoy 1-Sep-13 7:51am    
exactly,+5
Joezer BH 1-Sep-13 8:02am    
Thank you ridoy!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900