我程序中有这么两句话,为什么我在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;

解决方案 »

  1.   

    string sql="";
    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;
    }
      

  2.   

    其实也不用上面那么操作的,你的问题只是少了空格,当你输入负数的时候,后面的就会变为注释了.如输入:-1得到:
    update statistic set should=should+-1,balance=balance--1
    改为string sql = "update statistic set should=should+" + add + ",balance=balance - " + add;就可以了.
      

  3.   

    sql = "update statistic set should=should+(" + add + "),balance=balance-(" + add + ")";=>update statistic set should=should+(-9.8765),balance=balance-(-9.8765) 

    update statistic set should=should+(9.8765),balance=balance-(9.8765) 没具体试。