【问题标题】:Insert into DataTable from DataTable从 DataTable 插入到 DataTable
【发布时间】:2011-08-10 21:36:40
【问题描述】:

我想在某些条件下将数据从一个 DataTable 插入到另一个 DataTable。我发现此链接很有用:http://social.msdn.microsoft.com/Forums/en-US/csharplanguage/thread/7a5d0f88-3e71-435a-ae3c-ff01d1ca22a2/ 但我无法将.ToList() 用于我的查询。我收到以下错误:

'System.Data.EnumerableRowCollection<System.Data.DataRow>' does not contain a definition for 'ToList' and no extension method 'ToList' accepting a first argument of type 'System.Data.EnumerableRowCollection<System.Data.DataRow>' could be found (are you missing a using directive or an assembly reference?)

有人可以帮我解决这个问题吗?

PS:我的查询:

(from crow in dtConfiguration.AsEnumerable()
                         where crow.Field<string>("FieldType") == "FL"
                         & crow.Field<string>("FieldName") != "DATEADDED"
                         & crow.Field<string>("FieldName") != "DATEMODIFIED"
                         select crow).ToList()

【问题讨论】:

  • 你有using System.Linq; 吗?
  • 您可能必须使用 System.Linq 命名空间..

标签: c# linq datatable ienumerable enumerable


【解决方案1】:

将以下语句添加到您的代码中:

using System.Linq;

【讨论】:

    【解决方案2】:

    我认为您需要参考 System.Data.DataSetExtensions commenly found at C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0\System.Data.DataSetExtensions.dll

    【讨论】:

    • 对不起,我没明白你的意思!!!我在 3 个月前问过这个问题,它已经解决了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-07-07
    • 1970-01-01
    • 2018-03-10
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多