c# - 使用 LINQ 查询 DataColumnCollection

标签 c# linq datatable asqueryable datacolumncollection

我正在尝试对 DataTable 的 Columns 属性执行一个简单的 LINQ 查询:

from c in myDataTable.Columns.AsQueryable()
    select c.ColumnName

但是,我得到的是:

Could not find an implementation of the query pattern for source type 'System.Linq.IQueryable'. 'Select' not found. Consider explicitly specifying the type of the range variable 'c'.

如何让 DataColumnCollection 与 LINQ 配合使用?

最佳答案

怎么样:

var x = from c in dt.Columns.Cast<DataColumn>()
        select c.ColumnName;

关于c# - 使用 LINQ 查询 DataColumnCollection,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/237201/

相关文章:

javascript - 通过服务器端渲染对 DataTable 进行排序

php - 将多行从一个表传输到另一个表

c# - 如何拦截来自 C# 客户端 Web 代理的出站和入站 Soap 消息

c# - 如何自动将外国引用命名为有意义的东西?

c# - 为什么这个 LINQ 抛出 "FormatException was unhandled"?

c# - 当没有要求和的内容时,Linq .Sum() 函数失败

c# - Entity Framework - 不映射到数据库表的抽象基类

c# - 找不到为 MVC 5 DropDownListFor 添加占位符的方法

c# - 流利的 Nhibernate : Query to retrieve distinct values

c# - 在更新到数据库之前编辑 DataTable 中的行