CString a;
a.Format("update CardInfo set LeaveMoney=LeaveMoney+'%s' where CardId='%s'",m_Count,m_CardId);ADO连接数据库,这句想实现的功能是:输入m_CardId、m_Count,在表CardInfo中让LeaveMoney加上m_Count,但是m_Count不是表中的字段。 在运行的时候报错请问该怎样写这个语句。

解决方案 »

  1.   

    这句没错,我要问你这个m_Count 是什么类型? 用 %s 来进行格式化. 你要清楚,这个是格式化字符串的
      

  2.   

    m_Count是CString的。
    如果LeaveMoney类型是money 该怎么改这句?
    如果LeaveMoney类型是char 呢?
      

  3.   

    %c...等,要看Money具体是什么类型
      

  4.   

    如果LeaveMoney类型是char 、m_Count是CString 该怎么写这个语句。
      

  5.   

    CString a;
    a.Format("update CardInfo set LeaveMoney=LeaveMoney+'%s' where CardId='%s'",m_Count,m_CardId);当LeaveMoney为char 、m_Count为CString时,运行程序还是要报错 ,大哥帮看哈嘛 ,怎么改啊?该怎么写这个语句啊?
      

  6.   

    这句SQL本身没错. LeaveMoney 不要char 类型,你原来的Meney 类型就行了.格式化的时候将单绰号去掉吧.不需要的. 不过要看你是不是其它地方的了
      

  7.   

    _RecordsetPtr m_Rst;
    m_Rst.CreateInstance(__uuidof(Recordset));
       CString a;
       a.Format("update CardInfo set LeaveMoney=LeaveMoney+'%s' where CardId='%s'",m_Count,m_CardId);
           try
      {
      m_Rst->Open(_variant_t(a),
          conn.GetInterfacePtr(),  
    adOpenDynamic,
      adLockOptimistic,
      adCmdText);
      }
      catch(_com_error *es)
      {
      AfxMessageBox(es->ErrorMessage());
      }
    整个语句就这样。路论上没有错,但是在运行的时候要报错。
    如果我把那条SQL语句换成a.Format("update CardInfo set LeaveMoney=LeaveMoney+100 where CardId='%s'",m_CardId); 则可以运行。 到底该怎么改啊???大哥些。