指定的转换类型无效错误C#请帮助 [英] Specified Cast Type not Valid Error C# please help
本文介绍了指定的转换类型无效错误C#请帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试从数据库中将一些值插入到图表中。第一列(X轴)是String类型,第二列(Y轴)是float类型。当我按下按钮时,我不断收到此错误Cast Type无效。请帮助
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
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);
}
推荐答案
X和Y都需要是数值。字符串不是图表控制点的有效类型。
X and Y both need to be numeric values. A string is not a valid type for a chart control point.
这篇关于指定的转换类型无效错误C#请帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文