i want to delete record which is selected in datagridview from database but i got error
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "DELETE FROM addcustomer WHERE ccount_No=" + dataGridView1.SelectedRows[0].Cells[0].Value.ToString() + "";
my.Open();
cmd.Connection = my;
cmd.ExecuteNonQuery();
error is
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
plz help me
Loading
ta muPosted Sep 5, 2013, 9:56 AM
still getting that error with your code
Mohan GopiPosted Sep 5, 2013, 6:53 AM
can you share me the ccount_No datatype .
string selectedvalue=dataGridView1.SelectedRows[0].Cells[0].Value.ToString() ;
SqlCommand cmd = new SqlCommand();
cmd.CommandText = "DELETE FROM addcustomer WHERE ccount_No=" +selectedvalue + "";
my.Open();
cmd.Connection = my;
cmd.ExecuteNonQuery();
Check what will be the selectedvalue string received.