Unable to use Live Charts with Data from a DataTable

  • 419 Views
  • Last Post 07 January 2019
Rafael Souza posted this 04 January 2019

Guys, good afternoon,

I am trying to adapt the code of this tutorial:

to instead of taking the data from an ADO.NET Entity Data Model pick up data from a datatable to build a graph.

But when i write the code below:

string strQuery = @"SELECT Count(BussKey) AS Total, Ano FROM teste GROUP BY Ano";
            DataTable data = mtdGetDadosAcDt(conexaoAccess0, strQuery);            
            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 data)
            {

            }

foreach can not operate on 'DataTable' type variables 'GetEnumerator'.

How should I adapt the video code to work with datatable?

admin posted this 07 January 2019

I think you should write

foreach (var x in data.Rows)
{
   //Do something
}
Close