Click here to Skip to main content
15,889,116 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I am trying to insert some values into a chart from a database. the first column (X axis) is a String type and the second column ( Y Axis) is float type. I keep getting this error "Cast Type not valid"when ever i press the button. Please help

C#
private void ViewGraphBtn_Click(object sender, EventArgs e)
  {
      try
      {
          Query = "SELECT *  FROM Products;";
          Reader = conn.ExecuteStatement(Query);

          while (Reader.Read())
          {
              this.chart1.Series["Series1"]
                         .Points.AddXY(Reader.GetString(1), Reader.GetInt64(4));
          }
      }
      catch (Exception ex)
      {
           MessageBox.Show(ex.Message);
      }
Posted
Updated 4-Feb-14 4:14am
v2

1 solution

X and Y both need to be numeric values. A string is not a valid type for a chart control point.
 
Share this answer
 
v2
Comments
1Future 4-Feb-14 10:21am    
so do I have to convert my String values to numeric? ... if so I keep getting this error:"Input string was not in a correct format "
thank you
Las
S Houghtelin 4-Feb-14 10:24am    
What are your string values? Please giva an example of the data. Is it"123.4" or is it "Product 14". What does the data consist of?
Sergey Alexandrovich Kryukov 4-Feb-14 11:03am    
Good catch, a 5.
—SA
S Houghtelin 4-Feb-14 11:05am    
Thanks Sergey! :)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900