简体   繁体   中英

linq with dataTable in c#

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.

You should iterate rows to achive it

var r = ds.Tables["Customers"].Rows
  .Cast<DataRow>()
  .Where(r => r["fieldName"].ToString() == "Test");

Hope this can help you.

LINQ to DataSet

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

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM