Can we use linq to query against a DataTable?

Can we use linq to query against a DataTable?
A. Yes
B. No
C. Either Yes or No
D. None of the mentioned
 
Answer: b
Explanation: We cannot use query against the DataTable’s Rows collection, since DataRowCollection doesn’t implement IEnumerable<T>. We need to use the AsEnumerable() extension for DataTable. As an example:
Code:
                    var results = from myRow in myDataTable.AsEnumerable() 
                    where myRow.Field<int>("RowNo") == 1 
                    select myRow;
 

Tìm kiếm

Back
Top