Foreach语句不能对'system.data.datatable'类型的变量进行操作 [英] Foreach statement cannot operate on variables of type 'system.data.datatable'
本文介绍了Foreach语句不能对'system.data.datatable'类型的变量进行操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
将数据表转换为列表后
显示错误
var datas = dtcombo;
ColumnSeries col = new ColumnSeries(){DataLabels = true,Values = new ChartValues< int>(),LabelPoint = Point => Point.Y.ToString()};
Axis ax = new Axis(){Separator = new Separator(){Step = 1,IsEnabled = false}};
ax.Labels = new List< string>();
foreach(数据中的var x)
{
col.Values.Add(x.total.value);
ax.Labels.Add(x.year.ToString());
}
用于将数据表值绑定到实时图表
请帮助
我尝试过:
使用foreach它的显示错误
foreach语句不能对'system.data.datatable'类型的变量进行操作...
解决方案
无法迭代DataTable,因为它不是集合。
可能你打算访问它的行:foreach(datas.Rows中的var x)
after i convert a datatable into a list
its shows a error
var datas = dtcombo;
ColumnSeries col = new ColumnSeries() { DataLabels = true, Values = new ChartValues<int>(), LabelPoint = Point => Point.Y.ToString() };
Axis ax = new Axis() { Separator = new Separator() { Step = 1, IsEnabled = false } };
ax.Labels = new List<string>();
foreach (var x in datas)
{
col.Values.Add(x.total.value);
ax.Labels.Add(x.year.ToString());
}
its for bind the datatable values to a livechart
please help
What I have tried:
using foreach its shows error
foreach statement cannot operate on variables of type 'system.data.datatable'...
解决方案
A DataTable can't be iterated, because it's not a collection.
Probably you meant to access it's rows:foreach (var x in datas.Rows)
这篇关于Foreach语句不能对'system.data.datatable'类型的变量进行操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文