本文介绍了如何解决错误“输入字符串格式不正确?"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
任何人都知道这...
这是价格范围的编码........但是执行时会产生错误,例如输入字符串的格式不正确" .......
Anyone know this......
this is the coding for price ranges........but while executing it produce error like" input string is not in correct format".......
protected void BulletedList3_Click(object sender, BulletedListEventArgs e)
{
string price = BulletedList3.Items[e.Index].Value;
if (con.State == ConnectionState.Closed)
{
con.Open();
}
if (Convert.ToInt32( price )< 500)
{
SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price='" + price + "' and status='A' and type='retail'", con);
SqlDataAdapter da = new SqlDataAdapter(cmd);
DataSet ds = new DataSet();
da.Fill(ds);
DataList1.DataSource = ds;
DataList1.DataBind();
con.Close();
}
}
推荐答案
int i = Convert.ToInt32( price );
if (i < 500)
{
SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price=@PR and status='A' and type='retail'", con);
cmp.Parameters.AddWithValue("@PR", i);
这篇关于如何解决错误“输入字符串格式不正确?"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!