LINQ query on a DataTable or Dataset

60
Views
1
Answers

Hi,
How do I perform a LINQ query on a Datatable or Dataset?

edit | flag
William Patrick
Asked on: Dec 06, 2011 at 12:29AM

1 Answers

79
3
79

You can use with the AsEnumerable() extension for DataTable. Like using LINQ to Dataset

var results = from myRow in myDataTable.Rows where myRow.Field("RowNo") == 1 select myRow;

or into a new class like

var query = from p in dt.AsEnumerable()
                   
where p.Field("conditionfiled") == "condition"
                   
select new class
                   
{
                        name
= p.Field("name"),
                        age
= p.Field("age")                        
                   
};
edit | flag
Gokul A
Answered on: Dec 06, 2011 at 12:34AM

Post your Answer

Search

Welcome to Ask Amoeba!
This is 100% free and interactive site for sharing professional Questions and Answers, Opensource projects, Interview questions.
Learners, beginners, Experts stop and share your knowledge and ideas!

Browse Categories

Browse Tags