Link to home
Start Free TrialLog in
Avatar of John Porter
John PorterFlag for United States of America

asked on

Accessing SQL data in a Chart Object Windows Forms VS 2012 C#

Hello Experts,

I am trying to populate a Chart with SQL Data and cannot get it to work. I am using Visual Studio 2012 with C# and SQL Server 2008.

Below is the code on my Windows form.

SqlConnection con = new SqlConnection("server= Localhost;uid=sa;pwd=12345;database=MyDB;");
SqlCommand cmd = new SqlCommand("SELECT * FROM MyTable", con);
SqlDataReader mydatareader;
try
{
con.Open();
      mydatareader = cmd.ExecuteReader();
      while (mydatareader.Read())
            {
this.chart1.Series["Lot"].Points.AddXY(mydatareader.GetInt32("Lot"), mydatareader.GetDouble("Weight"));
                              
            }
}//end try
catch {}

The build messages I get are:

Error      1      The best overloaded method match for 'System.Data.Common.DbDataReader.GetInt32(int)' has some invalid arguments      D:\DataHarvestSystems\EHarvest 2016\OPI_Quota_Project\APP\EHarvestOPI_2015\EHarvestOPI_2015\ChartsForm_SF_Harvest.cs      65      49      EHarvestOPI_2015

Error      2      Argument 1: cannot convert from 'string' to 'int'      D:\DataHarvestSystems\EHarvest 2016\OPI_Quota_Project\APP\EHarvestOPI_2015\EHarvestOPI_2015\ChartsForm_SF_Harvest.cs      65      71      EHarvestOPI_2015

Error      3      The best overloaded method match for 'System.Data.Common.DbDataReader.GetDouble(int)' has some invalid arguments      D:\DataHarvestSystems\EHarvest 2016\OPI_Quota_Project\APP\EHarvestOPI_2015\EHarvestOPI_2015\ChartsForm_SF_Harvest.cs      65      86      EHarvestOPI_2015

Error      4      Argument 1: cannot convert from 'string' to 'int'      D:\DataHarvestSystems\EHarvest 2016\OPI_Quota_Project\APP\EHarvestOPI_2015\EHarvestOPI_2015\ChartsForm_SF_Harvest.cs      65      109      EHarvestOPI_2015


Can anyone see what is going on here?

Thanks!
ASKER CERTIFIED SOLUTION
Avatar of Carl Tawn
Carl Tawn
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of John Porter

ASKER

That was it - Thank you sir