【问题标题】:not able to use CopyToDataTable in linq for returning dataset无法在 linq 中使用 CopyToDataTable 来返回数据集
【发布时间】:2010-07-22 06:39:17
【问题描述】:

如何在 .net 3.5 中从 linq 返回 dataset

我在某些网站上看到使用了 CopyToDataTable 方法,但我无法使用该方法,因为我在参考列表中找不到 System.data.datatableextensions 参考。 请帮帮我。

感谢和问候, 维纳

【问题讨论】:

    标签: linq datatable linq-to-dataset


    【解决方案1】:

    这也适用于 VB.NET,只是你必须将查询变量声明为 IEnumerable(Of DataRow) 而不是只放置 Dim 关键字。

    【讨论】:

      【解决方案2】:

      直接从here复制。在询问之前尝试搜索

      // Fill the DataSet.
      DataSet ds = new DataSet();
       FillDataSet(ds);
      
      DataTable orders = ds.Tables["SalesOrderHeader"];
      
      IEnumerable<DataRow> query =
          from order in orders.AsEnumerable()
          where order.Field<DateTime>("OrderDate") > new DateTime(2001, 8, 1)
          select order;
      
      DataTable boundTable = query.CopyToDataTable<DataRow>();
      
      bindingSource.DataSource = boundTable;
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-06-08
        • 2014-04-10
        相关资源
        最近更新 更多