且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何解决错误“输入字符串格式不正确?"

更新时间:2023-09-13 15:15:10

请改用参数化查询-并将您之前转换后的价格提供给它.无论如何,您都在进行转换,所以为什么不正确使用该值呢?
Use a parametrized query instead - and feed it the converted price you did earlier. You are doing the conversion anyway, so why not use the value properly?
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);


检查一次数据库中为Price 给出的数据类型
并在代码中.如果它们不相同,则需要转换代码侧变量的数据类型
Check once what data type you have given for Price in database
and in code. If they are not same you need to convert the data type of code side variable


伙计……看看您输入的方式是否正确,那么您将不会得到此错误.例如,如果您要买东西,您将输入从2000到4000的奖金范围...就像您必须手动输入正确的输入字符串一样
hey buddy... see if you give your input in correct way, then u wont get this error... for example if you going to buy something, u will enter prize range starts from 2000 to 4000 ... as like you have to give correct input strings manually