我正在尝试使用以下代码从数据集中检索数据:
var all_pepole = from rows_of_bank in ds1.Tables[0].Rows select rows_of_bank;
foreach (System.Data.DataRow row in all_pepole)
{
Console.WriteLine("{0} {1} is {2} years old.", row[0].ToString(), row[1].ToString(), row[2].ToString());
}
但是这个代码会给我带来错误,这是错误的:
Could not find an implementation of the query pattern for source type 'System.Data.DataRowCollection'. 'Select' not found. Consider explicitly specifying the type of the range variable 'rows_of_bank'
1 回答
ds1.Tables[0].Rows
的类型为DataRowCollection
,它实现IEnumerable
但不实现IEnumerable<DataRow>
. 大多数Linq运算符仅适用于通用接口 . 您可以将项目转换为DataRow
,如下所示:或者您可以使用Linq中的
AsEnumerable
扩展方法到DataSet: