我程序中有这么两句话,为什么我在text中输入的是正数的时候,数据库中should可以增加,并且balance也能减少,但是当在text中输入负数的时候,数据库中should也能减少,但是balance却毫无变化呢?难道在转换的时候会把负号一起给转换没了?如果是这样的话,那应该should也不会减少才对啊?我应该怎么做呢?float add = float.Parse(this.tbshould.Text);
string sql = "update statistic set should=should+" + add + ",balance=balance-" + add;
string sql = "update statistic set should=should+" + add + ",balance=balance-" + add;
if(add>0)
{
sql = "update statistic set should=should+" + add + ",balance=balance-" + add;
}
else
{
int num = -add;
sql = "update statistic set should=should+" + add + ",balance=balance+" + num;
}
update statistic set should=should+-1,balance=balance--1
改为string sql = "update statistic set should=should+" + add + ",balance=balance - " + add;就可以了.
或
update statistic set should=should+(9.8765),balance=balance-(9.8765) 没具体试。