DataTable不包含AsEnumerable的定义

时间:2021-07-16 16:54:47

Using linq to query a datatable returns the following error: CS0117: 'DataSet1.map DataTable' does not contain a definition for 'AsEnumerable'

使用linq查询数据表会返回以下错误:CS0117:'DataSet1.map DataTable'不包含'AsEnumerable'的定义

Project includes reference for System.Data.Datasetextensions.

Project包含System.Data.Datasetextensions的参考。

Here's the code.

这是代码。

using System;
using System.Collections;
using System.ComponentModel;
using System.Configuration;
using System.Reflection;
using System.Data;
using System.Linq;
using System.Data.Linq;
using System.Data.Common;
using System.Data.DataSetExtensions;
using System.Linq.Expressions;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;

protected void Page_Load(object sender, EventArgs e)
    {
        var query1 = from mfg_nm in DataSet1.mapDataTable.AsEnumerable()

                     select mfg_nm;
}

running it w/out AsEnumerable() results in

运行它没有AsEnumerable()导致

var query1 = from mfg_nm in DataSet1.mapDataTable

                     select mfg_nm;

CS1660: Cannot convert lambda expression to type 'string' because it is not a delegate type

CS1660:无法将lambda表达式转换为'string'类型,因为它不是委托类型

thanks in advance for your help

在此先感谢您的帮助

3 个解决方案

#1


57  

The method you want is in the System.Data namespace, so that using directive is fine, but you also need a reference to the System.Data.DataSetExtensions assembly. Are you sure you've got that reference as an assembly reference?

您想要的方法是在System.Data命名空间中,因此using指令很好,但您还需要对System.Data.DataSetExtensions程序集的引用。您确定您已将该参考作为装配参考吗?

It's not clear why you've got a using directive for a System.Data.DataSetExtensions namespace - does that not raise an error?

目前尚不清楚为什么你有一个System.Data.DataSetExtensions命名空间的using指令 - 这不会引发错误吗?

What is the exact error with the AsEnumerable() call? (I'm surprised about the error you're getting with the second form... that's not the error I'd have expected.)

AsEnumerable()调用的确切错误是什么? (我对第二种形式的错误感到惊讶......这不是我预期的错误。)

#2


7  

In all cases where this happens, the reference to System.Data.DataSetExtensions.dll was missing. If in doubt, try creating a simple console project targeting .NET 4 with a reference to System.Data.DataSetExtensions.dll, to verify that adding the reference actually works.

在发生这种情况的所有情况下,都缺少对System.Data.DataSetExtensions.dll的引用。如果有疑问,请尝试创建一个针对.NET 4的简单控制台项目,并引用System.Data.DataSetExtensions.dll,以验证添加引用是否确实有效。

Also note that you only need to use the System.Data namespace.

另请注意,您只需要使用System.Data命名空间。

BTW mapDataTable is a DataTable, right?

BTW mapDataTable是一个DataTable,对吧?

#3


2  

Google search "system.data.datatable does not contain a definition for asenumerable" brought me here, and my trouble was missing:

谷歌搜索“system.data.datatable不包含asenumerable的定义”把我带到了这里,我的麻烦丢失了:

using System.Data;

Due to my implement the error message was a bit misleading. Hence, my answer to this question. Code was like...

由于我的实现,错误消息有点误导。因此,我对这个问题的回答。代码就像......

public List<mytype> MyMethod(params) {
   return new mynamespace.myclasslib.myclass().GetDataTable(params).AsEnumerable()
      .etc
}

Once I tried to explicitly declare the DataTable, it became obvious that I was missing the using statement.

一旦我尝试显式声明DataTable,很明显我错过了using语句。

#1


57  

The method you want is in the System.Data namespace, so that using directive is fine, but you also need a reference to the System.Data.DataSetExtensions assembly. Are you sure you've got that reference as an assembly reference?

您想要的方法是在System.Data命名空间中,因此using指令很好,但您还需要对System.Data.DataSetExtensions程序集的引用。您确定您已将该参考作为装配参考吗?

It's not clear why you've got a using directive for a System.Data.DataSetExtensions namespace - does that not raise an error?

目前尚不清楚为什么你有一个System.Data.DataSetExtensions命名空间的using指令 - 这不会引发错误吗?

What is the exact error with the AsEnumerable() call? (I'm surprised about the error you're getting with the second form... that's not the error I'd have expected.)

AsEnumerable()调用的确切错误是什么? (我对第二种形式的错误感到惊讶......这不是我预期的错误。)

#2


7  

In all cases where this happens, the reference to System.Data.DataSetExtensions.dll was missing. If in doubt, try creating a simple console project targeting .NET 4 with a reference to System.Data.DataSetExtensions.dll, to verify that adding the reference actually works.

在发生这种情况的所有情况下,都缺少对System.Data.DataSetExtensions.dll的引用。如果有疑问,请尝试创建一个针对.NET 4的简单控制台项目,并引用System.Data.DataSetExtensions.dll,以验证添加引用是否确实有效。

Also note that you only need to use the System.Data namespace.

另请注意,您只需要使用System.Data命名空间。

BTW mapDataTable is a DataTable, right?

BTW mapDataTable是一个DataTable,对吧?

#3


2  

Google search "system.data.datatable does not contain a definition for asenumerable" brought me here, and my trouble was missing:

谷歌搜索“system.data.datatable不包含asenumerable的定义”把我带到了这里,我的麻烦丢失了:

using System.Data;

Due to my implement the error message was a bit misleading. Hence, my answer to this question. Code was like...

由于我的实现,错误消息有点误导。因此,我对这个问题的回答。代码就像......

public List<mytype> MyMethod(params) {
   return new mynamespace.myclasslib.myclass().GetDataTable(params).AsEnumerable()
      .etc
}

Once I tried to explicitly declare the DataTable, it became obvious that I was missing the using statement.

一旦我尝试显式声明DataTable,很明显我错过了using语句。

相关文章