Kinjal Sonachhatra

Kinjal Sonachhatra

  • NA
  • 101
  • 20.7k

Update button Condition

Dec 19 2018 12:07 AM
private void btnUpdate_Click(object sender, EventArgs e)
{
Entity ent = new Entity();
BAL b = new BAL();
ent.intId = (int)gvData.SelectedRows[0].Cells["Id"].Value;
if (ent.intId != 0)
{
ent.strEmail = txtEmail.Text;
ent.strName = txtName.Text;
ent.strSalary = txtSalary.Text;
DL dl = new DL();
dl.Update(ent);
DataTable dt = dl.Display(ent);
gvData.DataSource = dt;
}
b.Clear(ent);
txtEmail.Text = txtName.Text = txtSalary.Text = " ";
}
 
 
 
Hello,
This is my Code for update. Now i want to put condition for update. Like if I put new record and by mistake I click Update then I got ("Index was out of range. Must be non-negative and less than the size of the collection.") Error. So I want to remove it. 
If you have any idea then Please Suggest.
Thanks in advance 

Answers (1)