ADO中使用insert into,其中一个参数用getDate(),另一个参数为变量时会出现错误:error C2110: cannot add two pointerschar       strVTRNum[6];
pConn->Execute("INSERT INTO t_LogDubErrors(tDubDateTime, strDubDevID)"
"VALUES (getDate(), '"+strVTRNum+"')", &RecordsAffected, adCmdText);如果把第二个参数该为字符串常量则不会出错
请教下大家这个问题怎么解决?

解决方案 »

  1.   

    C++ 里面字符串不能直接相加用strcat , 或者用类先连接起来(CString, _bstr_t)
      

  2.   

    char       strVTRNum[6];
    pConn->Execute("INSERT INTO t_LogDubErrors(tDubDateTime, strDubDevID)"
    "VALUES (getDate(), '"+strVTRNum+"')", &RecordsAffected, adCmdText);
    应该是:
    CString str = "";
    CString strNum(strVTRNum);
    CString strDate = "";//这个地方需要填写为需要转化的日期。
    str.Format("insert into t_LogDubErrors(tDubDateTime, strDubDevID) values('%s', '%s')", strDate, strNum);
      

  3.   


    /////////////////////////////////////////////////////////////CString strSQL;strSQL.Format("INSERT INTO t_LogDubErrors(tDubDateTime, strDubDevID) VALUES (getDate(), '%s'",strVTRNum);pConn->Execute((_bstr_t)strSQL,NULL,adCmdText);/////////////////////////////////////////////////////////////试试看!
      

  4.   

    谢谢楼上几位,不过没用MFC,是windows C,只有string,试了下实现相同的功能,没成功...
      

  5.   

    不用MFC, strcat _bstr_t 可以啊
      

  6.   

    char strSQL[100] = "INSERT INTO t_LogDubErrors(tDubDateTime, strDubDevID) VALUES (getDate(), '"; strcat(strSQL, strVTRNum);
     strcat(strSQL, "')") pConn->Execute((_bstr_t)strSQL,&RecordsAffected,adCmdText);这样试了,提示:missing ';' before identifier 'pConn',可能没写对,楼上能不能详细点儿?
      

  7.   

    strcat(strSQL, "')")-> strcat(strSQL, "')");
      

  8.   

    汗只注意到pConn这句没注意到上面的
    谢谢楼上提醒 
    问题解决
    给分