Answers for "linq datatable"

C#
0

c# datatable to linq

//You can't query against the DataTable's Rows collection, since 
//DataRowCollection doesn't implement IEnumerable<T>. 
//You need to use the AsEnumerable() extension for DataTable

var results = from myRow in myDataTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1
select myRow;


//AsEnumerable() returns IEnumerable<DataRow>. 
//If you need to convert IEnumerable<DataRow> to a DataTable,
//use the CopyToDataTable()
Posted by: Guest on July-28-2020
0

linq datatable

//Reference System.Data.DataSetExtensions
//Be carefull to data types
int id = 1;
//one row
DataRow r = (from DataRow m in myTable.Rows where m.Field<int>("col_name") == id select m).FirstOrDefault();
//list of rows
List<DataRow> r = (from DataRow m in myTable.Rows where m.Field<int>("col_name") == id select m).ToList();
Posted by: Guest on February-11-2021
0

LINQ query on a DataTable C#

var results = from myRow in myDataTable.AsEnumerable()
where myRow.Field<int>("RowNo") == 1
select myRow;
Posted by: Guest on July-24-2021

C# Answers by Framework

Browse Popular Code Answers by Language