Michael
Michael

Reputation: 13614

How to delete a row in datatable using linq to dataset?

I have table(Color) in DataSet(dsObjets).

I want to remove specific row(specific ColorID) from this table.

Any idea how can I implement this with help of LINQ?

Upvotes: 0

Views: 6180

Answers (2)

Tilak
Tilak

Reputation: 30698

Try this

var results = from row in dsObjects.Tables["Color"].AsEnumerable()
          where row.Field<int>("ColorID") == <color ID to be removed> 
          select row;
foreach (DataRow row in results)
{
   dsObjects.Tables["Color"].Remove(row);
}

Upvotes: 1

roeland
roeland

Reputation: 6336

Here is more information on deleting records: http://msdn.microsoft.com/en-us/library/bb386925.aspx

To delete a row in the database:

  • Query the database for the row to be deleted.
  • Call the DeleteOnSubmit method.
  • Submit the change to the database.

Upvotes: 1

Related Questions