Hi, I'm trying to get some data from an Access database to populate a chart.
I have the data but I'm not sure how to loop through it.
these two values are underlined and it says - The name 'data' does not exist in the current conext
data.ProductName;
data.UnitPrice;
private void creatChart() { Chart chart = new Chart(); chart.Width = 400; chart.Height = 300; string myConnStr = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=C:\\WPFtoSQL\\App_Data\\Northwind.mdb; User Id=admin; Password="; OleDbConnection myConn= new OleDbConnection (myConnStr); myConn.Open(); string myQuery = " SELECT * From Products"; OleDbCommand cmd = new OleDbCommand(myQuery, myConn); OleDbDataAdapter da = new OleDbDataAdapter(cmd); DataTable dt = new DataTable(); da.Fill(dt); DataSet dataset = new DataSet(); da.SelectCommand = cmd; DataSeries ds = new DataSeries(); foreach (DataRow dataRow in dt.Rows) { DataPoint dp = new DataPoint(); dp.AxisXLabel = data.ProductName; dp.YValue = Convert.ToDouble(data.UnitPrice); ds.DataPoints.Add(dp); } chart.Series.Add(ds); LayoutRoot.Children.Add(chart); }
Thanks v much