Linq select from datatable help

G

GiJeet

Hi, I have a datatable with your typical ID column and a notes
column. I'm trying to get the notes for a specific id passed to my
method.

Lanquage: C#
datatable is dtConfig
iID is passed into the method

Here is my (non-working :) ) linq code:

var sNotes = (from row in dtConfig.AsEnumerable()
where row.Field<int>("ID") == iID
select row.Field<String>("Notes"));

What am I doing wrong?

PS: I'd like to return a string rather then a var if possible, ie:
string sNotes = ....

Thanks.
G
 
G

GiJeet

Nevermind, I found the issue. I needed to add FirstOrDefault() to
the end. Now it works ok.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top