我需要将结果推送到数组中才能在图表中显示。我不断获得System.Data.DataRow
而不是价值。我需要知道,存储结果的正确方法(目前我将其存储在DataTable
中),并将其推送到数组中。我是c#中的新手..
public void getOutstanding()
{
SelectQueryBuilder sqbSelect;
DataSet dsOutstanding;
sqbSelect = new SelectQueryBuilder();
sqbSelect.SelectColumns(new string[] { "name"});
sqbSelect.SelectFromTable("user");
sqbSelect.AddWhere("category", Comparison.Equals, "18");
dsOutstanding = Conn.DataAdapter(CommandType.Text, sqbSelect.BuildQuery());
sqbSelect = null;
DataTable areaChart = dsOutstanding.Tables[0];
for( int a = 0; a < areaChart.Rows.Count; a++) {
// want to push the value to an array ;
}
}
谢谢..
答案 0 :(得分:1)
您可以使用此语法阅读。
string[] array = new string[areaChart.Rows.Count];
for( int a = 0; a < areaChart.Rows.Count; a++) {
array[a] = areaChart.Rows[a]["name"].ToString();
}
答案 1 :(得分:1)
您可以通过使用列名
索引DataRow
来访问列数据
var names = new string[areaChart.Rows.Count];
for (var index = 0; index < areaChart.Rows.Count; index++)
names[index] = areaChart.Rows[index]["name"].ToString();