Update Row In Datatable Using Linq Distinct

Update Row In Datatable Using Linq Distinct

You could also enumerate DataTable.Rows in a foreach and use if. The question clearly states 'Update two columns in a DataTable using LINQ' and your solution is. No Mta Installed Discarding Output Debian Linux more. Update DataTable Column. Visual Studio. And I used a variation of it to find distinct rows. You a typed collection you can use LINQ against without.

You could simply store the result since you are selecting the same DataRows twice. But the ToList is redundant since DataTable.Select already returns a collection, hence your doubling the required memory for nothing. The LINQ approch you've accepted does not need another collection (than the DataTable) at all. The foreach enumerates the query directly. You could also enumerate DataTable.Rows in a foreach and use if(condition.) to check if this row must be updated. That would be the most efficient and direct approach.

– Nov 8 '13 at 10:33.

Thanks for your quick reply. I realize that I stated something incorrectly in my original phrasing of the question, which I've fixed. And so I sort of agree with your answer (based on my bad info). Being a VB.NET developer, this is how I could code this situation without LINQ: For Each drTest As DataRow In mdtInspectionTests.Rows drTest(InspectionTest.Select) = False Next For Each drTemplateTest As DataRow In mdtServiceTemplateInspectionTests.Rows For Each drTest As DataRow In mdtInspectionTests.Rows If drTemplateTest(ServiceTemplateInspectionTest.InspectionTestID) = _ drTest(InspectionTest.InspectionTestID) Then drTest(InspectionTest.Select) = True End If Next Next But the reason I asked the question was to learn about how to code using LINQ. How would I accomplish this with LINQ to DataTable?