Gaurav Jadhav

Gaurav Jadhav

  • NA
  • 6
  • 4.3k

how to add checked rows of datagridview into database

Mar 6 2013 7:35 AM
how to add checked rows of datagridview into database in visual studio 2010 windows application form.
plz help

i hd written this code but throwing error on CheckBox chkbx = (CheckBox)row.FindControl("chkbx"); this line.

foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                CheckBox chkbx = (CheckBox)row.FindControl("chkbx");

                if (chkbx .Checked == true )
                {
                    con.Close();
                    con.Open();
                    com.Connection = con;
                    string str = "insert into EmpDetails values ('" + row.Cells[2].Value.ToString() + "','" + row.Cells[3].Value.ToString() + "')";
                    com.CommandText = str;
                    dr = com.ExecuteReader();

                    MessageBox.Show("Success.....");
                    dr.Close();
                }

Answers (4)