The exception is thrown at line if (bool.Parse(row.Cells[0].Value.ToString())).
Exception details:
System.NullReferenceException: 'Object reference not set to an instance of an object.'
System.Windows.Forms.DataGridViewCell.Value.get returned null.
private void btnDeleteCategory_Click(object sender, EventArgs e)
{
foreach (DataGridViewRow row in CategoryGV.Rows){if (bool.Parse(row.Cells[0].Value.ToString())){string cs = ConfigurationManager.ConnectionStrings["aladin"].ConnectionString;SqlConnection con = new SqlConnection(cs);SqlCommand cmd = new SqlCommand("DELETE FROM lwpos_categories WHERE id= '" + Convert.ToInt32(row.Cells[1].Value) + "' ", con);con.Open();cmd.ExecuteNonQuery();con.Close();}}
MessageBox.Show("Deleted Successfully", "Successfull operation", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
Rajanikant HawaldarPosted Dec 2, 2019, 3:09 AM
Ronika JencyPosted Dec 2, 2019, 3:08 AM