System.ArgumentException C#,Chart

  c++, charts, windows

I have a command to get data from the database and its working fine,
since the data in the database is encrypted I decrypt it using my decrypting method inside a loop

Here is my code:

SqlCommand command = new SqlCommand("select s.ProductID, p.ProductDesc, YEAR(s.SalesDate)as year, ISNULL(sum(s.Qty), 0.0) as total from Sales as s INNER JOIN Products as p on s.ProductID = p.ProductID WHERE Status = 'Sold' GROUP BY YEAR(SalesDate), s.ProductID, p.ProductDesc", sqlconn);

SqlDataReader dr = command.ExecuteReader();
DataTable dt = new DataTable();

Series s1 = chartSales.Series["Series1"];
s1.ChartType = SeriesChartType.Doughnut;
s1.Name = "Sales";
var chart = chartSales;
dt.Load(dr);
chartSales.DataSource = dt;
foreach (DataRow row in dt.Rows)
{
    string x = Cryptor.Decode( row.Field<string>("ProductDesc"));
    chart.Series[s1.Name].XValueMember = x; 
    chart.Series[s1.Name].YValueMembers = "total";
}

When I add a breakpoint and check the data, the data is being decrypted but shows an error at the last ProductDesc(the data that is being decrypted).

Here is the error: System.ArgumentException: 'Column with name 'ProductDesc' was not found.' .

Source: Windows Questions

LEAVE A COMMENT