I'm trying to update my database using datagridview but it throws "Object reference not set to an instance of an object" exception below is my code:
foreach (DataGridViewRow dgRow in dataGridView1.Rows)
{
//string re = dgRow.Cells[0].Value.ToString();
string re =Convert.ToString(dgRow.Cells[0].Value.ToString());
string strQuery = "UPDATE unit_master SET unit='"+re.ToString()+"'";
SqlCommand scmd = new SqlCommand(strQuery,SqlConn);
scmd.ExecuteNonQuery();
}
SqlConn.Close();