hello friend i have datagridview in my project which have 8 column.
at many cases user not Enter. bank name ,branch,and etc but when i click on save button
it get error=object reference not set to an instance of an object
here is my code
for (int i = 0; i < dataGridView1.Rows.Count; )
{
AC_code = dataGridView1[0, i].Value.ToString();
SqlCommand cmd3 = new SqlCommand("select AC_CODE from accountd where compcode='" + Compcls.Gcomp_cd + "'and Name='" + AC_code + "'", con, trans);
AC_cod = cmd3.ExecuteScalar().ToString();
string ddd = dataGridView1[2, i].Value.ToString();
string eee = dataGridView1[1, i].Value.ToString();
string fff = dataGridView1[3, i].Value.ToString();
string cno = dataGridView1[5, i].Value.ToString();
string cdate= dataGridView1[6, i].Value.ToString();
string bank = dataGridView1[7, i].Value.ToString();
string branch = dataGridView1[8, i].Value.ToString();
string dgdat = "INSERT INTO VCHAMT (compcode,VOU_TYPE,VOU_NO,AMOUNT,VOU_DT,DR_CR,NARRATION,AC_CODE,CHEQUE_NO,CHEQUE_DT,BANK_NAME,BRANCH)values('" + Compcls.Gcomp_cd + "','" + vctype + "','" + txtvoucherno.Text + "','" + ddd + "','" + (Convert.ToDateTime(dateTimePicker1.Text)).ToString("yyyy/MM/dd") + "','" + eee + "','" + fff + "','" + AC_cod + "','"+cno+"','"+cdate+"','"+bank+"','"+branch+"')";
SqlCommand cmd1 = new SqlCommand(dgdat, con, trans);
cmd1.ExecuteNonQuery();
i++;
}
trans.Commit();
toolTip1.IsBalloon = true;
toolTip1.ToolTipIcon = ToolTipIcon.Info;
toolTip1.ToolTipTitle = "SAVED";
toolTip1.Show("SAVED", mainpanell, 0, 0, 2000);
}
catch (Exception Ex)
{
trans.Rollback();
MessageBox.Show(Ex.Message);
}