日期:2014-05-20  浏览次数:20673 次

怎样取出LINQ查询出来的字段的值?
var q = from c in dc.Customers select c;

怎样出去每一行每一列的值,如要取出每行CustomerId的值

------解决方案--------------------
C# code

foreach(var r in q)
{
    Console.WriteLine(r.CustomerId);
}

------解决方案--------------------
var q = from c in dc.Customers select c.CustomerId;
------解决方案--------------------
咋不结贴呢,2楼的方法不行?
------解决方案--------------------
C# code


                var q = from c in db.Customers
                        select c.CustomerID;
                foreach (var id in q)
                {

                    Response.Write(id + ",");
                }

------解决方案--------------------
假设CustomerId的类型是long,可以写:

var q = from c in dc.Customers select c; 
var r= from Customer c in q select c.id; //取出每行CustomerId的值