更新数据库中的付款 [英] Update Payment in database
本文介绍了更新数据库中的付款的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用更新查询来更新付款方式
I use update query to update the payment
SqlCommand cmd = new SqlCommand(UPDATE Bank SET Payment = (Payment - '"+tprice.Text +"') WHERE NICNO = '" + FN.Text + "'", con);
将会发生以下错误
操作数数据类型nvarchar对于减法运算符无效.
the following error will occur
Operand data type nvarchar is invalid for subtract operator.
推荐答案
该错误表示它的含义.您将价格文本框的内容括在引号中,从而使其成为字符串.另外,如果输入非数字,您的代码也会爆炸,并且如果有人聪明,由于SQL注入,他们可以使用您的代码擦除整个数据库.
The error means what it says. You''re putting the contents of the price textbox in quotes, which makes it a string. Also, your code will blow up if a non number is entered, and if someone is smart, they can use your code to erase your entire DB, due to SQL injection.
添加值参考的价格
cmd.parameter.addwithvalue("@ payment",tprice.text)
add value reference of tprice
cmd.parameter.addwithvalue("@payment", tprice.text)
我的疯狂猜测是您正在尝试这样做-
My wild guess is this is what you are trying to do -
SqlCommand cmd = new SqlCommand("UPDATE Bank SET Payment = '(Payment - "+tprice.Text +")' WHERE NICNO = '" + FN.Text + "'", con);
看看是否有帮助.
see if it helps.
这篇关于更新数据库中的付款的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文