I want to delete a DataRow in my MySql database, using Linq to search the row, and delete the row from the dataSet.
But it wouldn’t work to delete the row in my database.
My code:
var results = (from myRow in dataSet.Tables["Students_has_Courses"].AsEnumerable()
where myRow.Field<int>("Students_idStudents") == 1 && myRow.Field<int>("Courses_idCourses") == 1
select new { id = myRow }).ToList();
foreach (var x in results)
{
dataSet.Tables["Students_has_Courses"].Rows.Remove(x.id);
x.id.Delete();
}
dataAdapter.Update(dataSet);
What am I doing wrong?
Removing rows from a DataTable means not that they will be deleted from the database later.
If you want them to be deleted with a DataAdapter/TableAdapter, you need to call
Deleteon the DataRow. Then they will be marked withDataRowState.Deleted.