query dataset with linq

Hi

I have used ado.net to return a dataset
I now need to query the dataset with linq

i.e.

int event1Count = ds.where(eventId = 1);
int event2Count = ds.where(eventId = 2);

Open in new window


How can I achieve this ?
websssCEOAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dorababu MSenior Software EngineerCommented:
You can try as below
var results = from myRow in ds.AsEnumerable()
where myRow.Field<int>("eventId") == 1
select myRow;

Open in new window


You can apply or condition if you want to filter with 2
0
websssCEOAuthor Commented:
thanks
that code works with a data table and not data set
0
NorieAnalyst Assistant Commented:
websss

Which table in the dataset do you want to query?
1
käµfm³d 👽Commented:
A DataSet is a collection of DataTables. Just pick the table you want to iterate over from the Tables property. You can do that with LINQ also:

var matchingRows = ds.Tables
                     .OfType<DataTable>()
                     .FirstOrDefault(table => table.TableName == "X")
                     .AsEnumerable()
                     .Where(row => row.Field<int>("eventId") == 1);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
ASP.NET

From novice to tech pro — start learning today.