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.

cuongle
  • 74,024
  • 28
  • 151
  • 206
Pratik
  • 267
  • 4
  • 16

3 Answers3

1

You should iterate rows to achive it

var r = ds.Tables["Customers"].Rows
  .Cast<DataRow>()
  .Where(r => r["fieldName"].ToString() == "Test");
Viacheslav Smityukh
  • 5,652
  • 4
  • 24
  • 42
0

Hope this can help you.

LINQ to DataSet

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

Mico
  • 117
  • 1
  • 12
  • 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? – Pratik Jul 26 '13 at 09:46
  • Check this 3.5 version http://msdn.microsoft.com/en-us/library/bb386921%28v=vs.90%29.aspx – Mico Jul 26 '13 at 10:01
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

Bart
  • 29
  • 4