here is my code
for (int i = 0; i < dataGridView1.Rows.Count; i++)
{
SqlCommand cmd3 = new SqlCommand("select AC_CODE from accountd where compcode='" + Compcls.Gcomp_cd + "'and Name='" + dataGridView1[0, i].Value.ToString() + "'", con, trans);
AC_cod = cmd3.ExecuteScalar().ToString();
string dgdat = "INSERT INTO VCHAMT (compcode,VOU_TYPE,VOU_NO,AMOUNT,VOU_DT,DR_CR,NARRATION,AC_CODE)values('" + Compcls.Gcomp_cd + "','" + vctype + "','" + txtvoucherno.Text + "','" + dataGridView1[2, i].Value.ToString() + "','" + (Convert.ToDateTime(dateTimePicker1.Text)).ToString("yyyy/MM/dd") + "','" + dataGridView1[1, i].Value.ToString() + "','"+dataGridView1[3,i].Value.ToString()+"','" + AC_cod + "')";
SqlCommand cmd1 = new SqlCommand(dgdat, con, trans);
cmd1.ExecuteNonQuery();
}
if user not enter value in
dataGridView1[1, i].Value.ToString()
it gives error=
Object reference not set to an instance of an object.
i want handle error can any buddy tell me any idea that how handle this error