如何将varchar转换为float. [英] how to convert varchar to float.

查看:676
本文介绍了如何将varchar转换为float.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这里附有我的编码,它显示以下错误,任何人都可以纠正该错误.

错误:

here with attched my coding it shows following error can anyone correct the error.

Error:

Error converting data type varchar to float.



错误编码:




Error Codding:


price_range = BulletedList3.Items[e.Index].Value;
       if (con.State == ConnectionState.Closed)
       {
           con.Open();
       }
       SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price= ''" + price_range + "''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();

推荐答案

如果您的价格列在数据库中是浮动的

用它
if your price column is float in Database

use it
SqlCommand cmd = new SqlCommand("select pro_img,pro_name,price from product where price= " + price_range.ToString() + " and status='A' and type='retail' ", con);


在转换时使用float.tryparse.要使用它,否则请点击此链接


http://msdn.microsoft.com/en-us/library/994c0zb1.​​aspx [ ^ ]
Use float.tryparse while conversion.. I think you know how to use it , if not then follow this link


http://msdn.microsoft.com/en-us/library/994c0zb1.aspx[^]


这篇关于如何将varchar转换为float.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆