abdujalil  chuliev

abdujalil chuliev

  • 1.3k
  • 400
  • 41k

checkbox gridview insert mysql

Sep 30 2015 6:44 AM
I know how to upload and insert using FileUpload ToolBox control.
But these time I have to insert selected gridView item(an image) to mysql using asp.net.
My codes are given below.
How can I fix it?
Examples will be much appriciated.

protected void ImageInsert()
{
{
MySqlConnection con = new MySqlConnection(constr);
MySqlCommand cmd = new MySqlCommand("INSERT INTO Images(Image) VALUES ('"+CheckBox().ToString()+"')", con);
con.Open();
int s1 = cmd.ExecuteNonQuery();
if (s1 > 0)
{
imgUp1.Text = "Image Uploaded succesfully!";
}
con.Close();
}
}
private string CheckBox()
{
string url=null;
foreach (GridViewRow row in gvImages.Rows)
{
CheckBox chkBox = row.FindControl("chkRow") as CheckBox;
if (chkBox !=null && chkBox.Checked)
{
Image img = (Image)row.Cells[1].Controls[1];
url = img.ImageUrl;
}
}
return url;
}

Answers (5)