比如要修改students表中的多个字段,是不是这样不对?
cstring str;
str.format("update students set name=%s and sex=%s and age=%d where ID=%d",xingming,xingbie,nianling,bianhao);
ado.pConn->Execute((_bstr_t)str,NULL,adCmdText);但结果老是有什么语法错误?到底正确的格式是怎样的啊?谢谢了!

解决方案 »

  1.   

    CString str;
    str.format("update students set name=\"%s\" and sex=\"%s\" and age=%d where ID=%d", xingming, xingbie, nianling, bianhao);
    ado.pConn->Execute((_bstr_t) str, NULL, adCmdText);
      

  2.   

    它说关键字and附近有语法错误啊。
      

  3.   

    str.format("update students set name='%s' and sex='%s' and age=%d where ID=%d",xingming,xingbie,nianling,bianhao);%s对应的字符串,要在%s两边加上单引号
      

  4.   

    str.Format("update pengyou set zhiye='%s' and dianhua='%s' and nianling=%d where ID=19",m_zhiye,m_dianhua,m_nianling);
    try
    {
    ado.pConn->Execute((_bstr_t)str,NULL,adCmdText);
                            }
                            catch(_com_error e)
    {
    AfxMessageBox(e.Description());
    }
    那这次我加了啊,还是说关键字and附近有语法错误,这困扰我好久了。
      

  5.   

    补充说下:m_zhiye是我在界面关联的cstring变量,m_dianhua也是cstring变量,m_nianling为int型变量。
      

  6.   


    把and改成英文的逗号试试