John Porter
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.Add XY(mydatar eader.GetI nt32("Lot" ), mydatareader.GetDouble("We ight"));
}
}//end try
catch {}
The build messages I get are:
Error 1 The best overloaded method match for 'System.Data.Common.DbData Reader.Get Int32(int) ' has some invalid arguments D:\DataHarvestSystems\EHar vest 2016\OPI_Quota_Project\APP \EHarvestO PI_2015\EH arvestOPI_ 2015\Chart sForm_SF_H arvest.cs 65 49 EHarvestOPI_2015
Error 2 Argument 1: cannot convert from 'string' to 'int' D:\DataHarvestSystems\EHar vest 2016\OPI_Quota_Project\APP \EHarvestO PI_2015\EH arvestOPI_ 2015\Chart sForm_SF_H arvest.cs 65 71 EHarvestOPI_2015
Error 3 The best overloaded method match for 'System.Data.Common.DbData Reader.Get Double(int )' has some invalid arguments D:\DataHarvestSystems\EHar vest 2016\OPI_Quota_Project\APP \EHarvestO PI_2015\EH arvestOPI_ 2015\Chart sForm_SF_H arvest.cs 65 86 EHarvestOPI_2015
Error 4 Argument 1: cannot convert from 'string' to 'int' D:\DataHarvestSystems\EHar vest 2016\OPI_Quota_Project\APP \EHarvestO PI_2015\EH arvestOPI_ 2015\Chart sForm_SF_H arvest.cs 65 109 EHarvestOPI_2015
Can anyone see what is going on here?
Thanks!
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
SqlCommand cmd = new SqlCommand("SELECT * FROM MyTable", con);
SqlDataReader mydatareader;
try
{
con.Open();
mydatareader = cmd.ExecuteReader();
while (mydatareader.Read())
{
this.chart1.Series["Lot"].
}
}//end try
catch {}
The build messages I get are:
Error 1 The best overloaded method match for 'System.Data.Common.DbData
Error 2 Argument 1: cannot convert from 'string' to 'int' D:\DataHarvestSystems\EHar
Error 3 The best overloaded method match for 'System.Data.Common.DbData
Error 4 Argument 1: cannot convert from 'string' to 'int' D:\DataHarvestSystems\EHar
Can anyone see what is going on here?
Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER