[英]How to read data from database and store to an array C#
I need to push the result into an array to be able to display in a chart . 我需要将结果推送到数组中才能显示在图表中。 I am keep getting System.Data.DataRow
instead of the value. 我一直在获取System.Data.DataRow
而不是值。 I need to know, the proper way to store the result(currently I store it in DataTable
), and to push it into an array.I am newbie in c# .. 我需要知道正确的方法来存储结果(当前我将其存储在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 ;
}
}
Thank you.. 谢谢..
You can read by using this syntax. 您可以使用此语法阅读。
string[] array = new string[areaChart.Rows.Count];
for( int a = 0; a < areaChart.Rows.Count; a++) {
array[a] = areaChart.Rows[a]["name"].ToString();
}
You can access column data by indexing DataRow
with column name 您可以通过使用列名索引DataRow
来访问列数据
var names = new string[areaChart.Rows.Count];
for (var index = 0; index < areaChart.Rows.Count; index++)
names[index] = areaChart.Rows[index]["name"].ToString();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.