【发布时间】:2015-05-27 11:06:22
【问题描述】:
我想把DataTable中列的项目提取出来放到List中。
这是我的列表和数据表:
List<int> product1 = new List<int>();
DataTable table = this.IoC.Resolve<ISurveyResultsService>().GetProduct(studyYear, productName);
我想遍历 DataTable 并将元素放入列表中。我试过这样:
foreach (var row in table.Rows)
{
product.Add((int)row["StudyID"]);
}
我收到一条错误消息“无法使用 [] 将索引应用于 'object' 类型的表达式”
知道如何尽可能简单地解决这个问题吗?
【问题讨论】: