abdujalil  chuliev

abdujalil chuliev

  • 1.3k
  • 400
  • 41k

insert selected image from datagrid in wpf

Oct 17 2015 11:54 AM
There is a DataGrid with bunch of images in my wpf application.
I have to select an image from my DataGrid and insert that image to mysql DB.
My code is not working properly.
I need help. My code is below.

private void btnImage_Click(object sender, RoutedEventArgs e)
{
{
string constr = "Data Source=localhost;port=3306;Initial Catalog=MyCollege;User Id=root;password=2525";
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("INSERT INTO images(Image) VALUES ('" + dataGrid1.SelectedValue + "')", con);
con.Open();
int s1 = cmd.ExecuteNonQuery();
if (s1 > 0)
{
lbl1.Content = "Image inserted succesfully";
}
con.Close();
}
}