Posts

Showing posts with the label linq to datatable tutorial

LINQ To DataTable

Sorry for not choosing bulk insert / update again in this post. I select this topic LINQ to DataTable because I think this is a very interesting topic to post. In one of the project  in my company, I saw many DataTable operations using the old style – dt.Select() method to filter DataRows. There are lots of chances of errors at run time because all conditions are simple strings written in “.Select()” method. If you have LINQ support in your project then LINQ to DataTable is the best way to filtering datarows from DataTable. This will also reduce run time errors and I also found that LINQ takes less time to execute then Select() method if amount of rows in DataTable is more. So, let’s start by creating one temporary DataTable. We will use this DataTable to understand LINQ to DataTable. Create new DataTable // Create new DataTable DataTable dtOrders = new DataTable (); // Add columns you need dtOrders.Columns.Add( "OrderID" , typeof ( int )); dtOrders.Columns.Add( "O...