2014-09-11 45 views
0

我試圖使用DataTableLINQ我用的nTier我的解決方案,但是,當我嘗試使用LINQDataTable它給了我一個錯誤:對不起,我的英語如何在DataTable中使用LINQ?

Error 1 Cannot convert lambda expression to type 'string' because it is not a delegate type c:\users\ba-ojt\documents\visual studio 2010\Projects\GoActiveDirectory\PresentationTier\Default.aspx.cs 21 25 PresentationTier 

我怎樣才能修復這個 以及它如何成爲一個lambda表達式?

mycode的:

protected void Page_Load(object sender, EventArgs e) 
    { 
     DataServiceReference.Service1Client newService = new DataServiceReference.Service1Client(); 
     DataTable dt = newService.GetAccounts(); 

     var query = from data in dt 
        select data;//Error Here 

     Repeater1.DataSource = query; 
     Repeater1.DataBind(); 

    } 

MyReference:

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Web; 
using System.Web.UI; 
using System.Web.UI.WebControls; 

using System.Data; 
using System.Data.Entity; 

回答

3

使用AsEnumerable()這樣的:

var query = from data in dt.AsEnumerable() 
      select data; 

更新: 然後擺脫你能做到這一點的數據表中的列:

data.Field<YourType>("YourColumnName") 

參考:

1

試試這個:

var query = (from DataRow data in dt.Rows 
      select data).ToList();