Hi,
I have a datagridview and a delete button.When user select a row and click delete button (outside of the datagridview) it must delete relevant row from datagridview.
Right now it is working but sometime it throws this error
"Column named RecordID cannot be found" from below highlighted line
int selectedIndex = InternetGroupDGV.CurrentCell.RowIndex;
if (selectedIndex > -1)
{
int selectedrowindex = InternetGroupDGV.CurrentCell.RowIndex;
DataGridViewRow selectedRow = InternetGroupDGV.Rows[selectedrowindex];
string recID = Convert.ToString(selectedRow.Cells["RecordID"].Value);
SqlConnection con = new SqlConnection(this.configuration.Connstring);
SqlCommand deleteCMD = new SqlCommand("InternetGroup_Delete", con);
deleteCMD.CommandType = CommandType.StoredProcedure;
deleteCMD.Parameters.AddWithValue("@RecordID", recID);
con.Open();
deleteCMD.ExecuteNonQuery();
callDB(); //Bind
}
else
{
MessageBox.Show("Error Occured");
}
Seems me once it deleted a record it cannot find out RecordID to delete again.
Any ideas?
Thanks
"Column named RecordID cannot be found" from below highlighted line
int selectedIndex = InternetGroupDGV.CurrentCell.RowIndex;
if (selectedIndex > -1)
{
int selectedrowindex = InternetGroupDGV.CurrentCell.RowIndex;
DataGridViewRow selectedRow = InternetGroupDGV.Rows[selectedrowindex];
string recID = Convert.ToString(selectedRow.Cells["RecordID"].Value);
SqlConnection con = new SqlConnection(this.configuration.Connstring);
SqlCommand deleteCMD = new SqlCommand("InternetGroup_Delete", con);
deleteCMD.CommandType = CommandType.StoredProcedure;
deleteCMD.Parameters.AddWithValue("@RecordID", recID);
con.Open();
deleteCMD.ExecuteNonQuery();
callDB(); //Bind
}
else
{
MessageBox.Show("Error Occured");
}
Seems me once it deleted a record it cannot find out RecordID to delete again.
Any ideas?
Thanks

Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 22, 2015, 2:24 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 21, 2015, 11:36 PM EDT
Jaipal ReddyRank #588 · 4.1K reputationPosted Jun 22, 2015, 1:40 AM EDT
Resign Designs35 reputationPosted Jun 22, 2015, 2:05 AM EDT
Jaipal ReddyRank #588 · 4.1K reputationPosted Jun 22, 2015, 2:17 AM EDT
Upendra Pratap ShahiRank #329 · 7.5K reputationPosted Jun 22, 2015, 4:24 AM EDT