0

I am using datatable on which I want to use Linq. but as i am new to linq i dont know how it uses. I google it I got lots of information which is not sufficient like. If I am using datatable and i got info like :

DataRow r = from dr in ds.Tables["Customers"].AsEnumerable() where dr.Field<Guid>("customerid").ToString() = row[2].ToString() select dr; dt.ImportRow(r); 

and I have lots of queries like what is "dr". dr.fields?, ".AsEnumerable()" is not present at my side.

Even this code also doesnt work:

IEnumerable<DataRow> r = from dr in ds.Tables["Customers"].Select().Where(x => x.Field<Guid>("customerid").ToString() == row[2].ToString()) select dr; 

So can anyone please give me link on which i got all information from beggining on linq.

6
  • code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b Commented Jul 26, 2013 at 9:33
  • have you including System.Linq in your class? Commented Jul 26, 2013 at 9:33
  • You need to add a reference to System.Data.DataSetExtensions.dll and make sure you have a using System.Data; directive in your file. Commented Jul 26, 2013 at 9:34
  • yes i have added System.Linq And i tried using DataSet but it doesnt work at all Commented Jul 26, 2013 at 9:35
  • Possible duplicate: stackoverflow.com/questions/10855/linq-query-on-a-datatable Commented Jul 26, 2013 at 9:35

3 Answers 3

1

You should iterate rows to achive it

var r = ds.Tables["Customers"].Rows .Cast<DataRow>() .Where(r => r["fieldName"].ToString() == "Test"); 
Sign up to request clarification or add additional context in comments.

Comments

0

Hope this can help you.

LINQ to DataSet

http://msdn.microsoft.com/en-us/library/bb386921.aspx

2 Comments

As per this link it is not working at my end means DataTable.AsEnumerable() is not appearing at my end(Framework 3.5) What is exact issue?
0

It's like a SQL select query, where dr is the * (that is, it is the returned data).

Some nice examples: http://code.msdn.microsoft.com/101-LINQ-Samples-3fb9811b

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.