Click here to Skip to main content
15,888,984 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
int j = dtview.CurrentRow.Index;
                                string query = "DELETE FROM Accounts WHERE Account_No=(Select Account_No from Customer where Customer_CNIC=@Customer_CNIC)";

                                SqlCommand cmd = new SqlCommand(query, cn);
                                cmd.Parameters.AddWithValue("@Customer_CNIC", dtview.Rows[j].Cells[4].Value);
                                cn.Open();
                                cmd.ExecuteNonQuery();
                                cn.Close();
                                MessageBox.Show("Record Deleted Successfully", "Success Message", MessageBoxButtons.OK, MessageBoxIcon.Information);
Posted
Comments
Menon Santosh 4-Jan-13 5:11am    
Where is the error ?

1 solution

Probably, the CurrentRow.Index is not set.
Check it is >= 0, and also check that it is less than the rows count. Then check you have at least five cells across. You will probably find that at some point, the event handler you are processing this from is being called before the table / view is fully populated.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900