输入的字符串格式不正确?为什么 [英] input string was not in correct format? why
本文介绍了输入的字符串格式不正确?为什么的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有人知道吗?
输入的字符串格式不正确?为什么
Can Anyone know?
input string was not in correct format? why
public float getshipping(string deliveryarea)
{
SqlCommand cmd3 = new SqlCommand("select shipping from delivery where status='A' and area='" + deliveryarea + "'", con);
SqlDataReader dr3 = cmd3.ExecuteReader();
while (dr3.Read())
{
shiping = float.Parse(dr3[0].ToString());//error
}
dr3.Close();
return shiping;
}
推荐答案
为什么不尝试使用Convert.ToDouble而不是float.parse
why don''t you try Convert.ToDouble instead of float.parse
确保dr3 [0]可以返回float ?,如果不是,请使用try parse代替float.parse,
希望对您有帮助,
谢谢
are you sure that dr3[0] can return float?, if it''s not the use try parse instead of float.parse,
hope it helps,
thanks
尝试一下:
try this:
float result;
float.TryParse(dr[3], out result)
{
shipping = result;
}
这是为了检查dr [3]的值是否可以转换为float.
如果这解决了您的问题,请标记为答案
-爱德华
this is to check if the value of dr[3] is convertible to float.
Please mark as answer if this solved your problem
-Eduard
这篇关于输入的字符串格式不正确?为什么的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文