How to perform a LINQ query on a datatable

1090415 pts.
Tags:
.NET
C
LINQ
For the past few weeks, I'm trying to perform a LINQ query on a datatable object but I'm having a ton of issues. Here's what I tried:
var results = from myRow in myDataTable
where results.Field("RowNo") == 1
select results;
But it's not working. Is there anything like this that works? Thanks.

Answer Wiki

Thanks. We'll let you know when a new response is added.

LINQ operates against sets that implement IEnumerable, which a datatable does not support by default.  However, using myDataTable.AsEnumberable() will convert the results to the proper format so LINQ can be used.

Discuss This Question: 1  Reply

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.
  • clark445kent
    Hi,
    Check this
    var results = from DataRow myRow in myDataTable.Rows
        where (int)myRow["RowNo"] == 1
        select myRow

    I hope it will be helpful for you.

    Thanks & Regard
    Clark Kent

    8,235 pointsBadges:
    report

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: