Remove Row through DataAdapter
13,233
Solution 1
You need to make sure you've set the da1.DeleteCommand - this is the command that will be fired for each row in the DataTable that has been deleted. See this MSDN reference for example.
Solution 2
What fixed it for me was to call the Delete
method on the DataRow
instead of the Remove
method on the DataTable
.
ds.Tables["localitati"].Rows.Find(primaryKeyValue).Delete();
or just simply
dr.Delete();
Author by
Alex
Updated on June 29, 2022Comments
-
Alex almost 2 years
I've initialized a dataAdapter :
string sql = "SELECT * From localitati"; da1 = new System.Data.SqlClient.SqlDataAdapter(sql, con); da1.Fill(ds1, "localitati");
And this works just fine. The problem is when i try to delete a record and update the database. I remove a record from the dataset as such :
ds1.Tables["localitati"].Rows.Remove(dRow);
And this works just fine as well(verified).
The problem is when i update the DataAdapter, the DataBase doesn't get modified :
con.Open() da1.Update(ds1, "localitati"); con.Close();
What could be the problem ?