_ConnectionPtr m_pConnection;
_RecordsetPtr pRstD(__uuidof(Recordset));
_RecordsetPtr pRst(__uuidof(Recordset));
    HRESULT hr;
try
{
hr=m_pConnection.CreateInstance("ADODB.Connection");

if(SUCCEEDED(hr))
{
hr=m_pConnection->Open("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=noshery","","",adModeUnknown);
}
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("连接数据库失败\r\n错误信息:%s",e.ErrorMessage());
AfxMessageBox(errormessage);
}
int num=1;
CString sSQL;

    sSQL.Format("update from 订单表 set 订单状态=%d where 订单号=%d",num,num);
pRst=m_pConnection->Execute((_bstr_t)sSQL,NULL,adCmdText);

解决方案 »

  1.   

    一般都是通过结果集来实现的: _bstr_t sql="select * from UserInformation where PhoneNumber='"+m_haoma+"'";

    HRESULT hr;
    //使用记录集来添加记录
    _RecordsetPtr Record;
    Record.CreateInstance(__uuidof(Recordset));
    try
    {
    hr=Record->Open(sql,
    m_pConnection.GetInterfacePtr(),
    adOpenDynamic,
    adLockOptimistic,
    adCmdText);
    if((Record->BOF)&&(Record->adoEOF))
    {  
    Record->Close();
    Record=NULL;
    return;
    }
    else{
    try{

    //写入每个字段
    Record->PutCollect("UserName",_variant_t(m_name));
    Record->PutCollect("ConnectWay",_variant_t(m_connection));
    Record->PutCollect("Re",_variant_t(m_re));
    Record->Update();
    }
    catch(...){
    Record->Close();
    Record=NULL;
    AfxMessageBox("修改失败!");
    return;
    }
    }
    }
    catch(_com_error *e)
    {
    e->ErrorMessage();
                    Record->Close();
            Record=NULL; return;
    }
    Record->Close();
    Record=NULL;
    AfxMessageBox("修改成功!");
      

  2.   

    sSQL.Format("update from 订单表 set 订单状态=%d where 订单号=%d",num,num); 
    应该是:
    sSQL.Format("update 订单表 set 订单状态=%d where 订单号=%d",num,num); 
    你多写了一个from 导致语法错误。