2

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. 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# ..

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..

2
  • 1
    What kind of chart are you using? Usually you can just bind a datatable to a chart like that: chart.DataSource = table; chart.DataBind(); Commented May 23, 2018 at 7:43
  • I am using Chart.js, and it need the data to be in array form.. Commented May 23, 2018 at 7:45

2 Answers 2

1

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();          
}
Sign up to request clarification or add additional context in comments.

Comments

1

You can access column data by indexing DataRow with column name

 var names = new string[areaChart.Rows.Count];

 for (var index = 0; index < areaChart.Rows.Count; index++)        
     names[index] = areaChart.Rows[index]["name"].ToString();  

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.