我想更新数据在一个表里,但表里的值总是不变,请大家看看是什么原因????谢谢我用的是vc --- SQL Server2000 ---- ADO方式//////////////////////////在OnInitDialog()中添加: strCnn="Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;User ID=sqlserver;Initial Catalog=server_data;Data Source=(local)"; m_pConnection.CreateInstance(__uuidof(Connection)); //创建connection对象实例       
m_pConnection->Open((_bstr_t)strCnn, "", "", adModeUnknown);///////////////////////////////////////////void CSERVERDlg::DBUpdateAccount(char account[16])
{  try{
            
       CString sTime = GetCurrentTime();  //得到当前时间       char tmp[256];
       _variant_t RecordsAffected;
       memset(tmp, 0, sizeof(tmp));

       sprintf(tmp, "UPDATE Account set time=%s where account=%s", sTime,account);
       m_pConnection->Execute(tmp, &RecordsAffected, adCmdText);  ?????????调试时运行到这里就跳到catch里了,上一步的tmp的值是正确的.
                 
    }catch(_com_error &e)
    {
 ::MessageBox(NULL,e.Description(),"更新错误",MB_OK);
    }}/////////////////////////////////////////////////在程序中调用:
    DBUpdateAccount(m_Account);

解决方案 »

  1.   

    "UPDATE Account set time='%s' where account='%s'"
    改成这样试试看看
      

  2.   

    time字段在数据库里是什么类型,如果字符串上面可以,如果是datetime
    就要
    CTime t = CTime::GetCurrentTime();
    CString sTime = t.Format( "%Y-%m-%d %H:%M:%S" );//"2006-11-01 12:30:20"
    .....sprintf(tmp, "UPDATE Account set time='%s' where account='%s'", sTime,account);
    注意要加单引号
      

  3.   


    对了,谢谢.是因为没有加update中没有加 '' 的原因,你后面说的我是这么做的.say thanks again!