我把一个evc4程序在VS2005中转换,但在2005下面报错,不知道是哪里的设置问题,大家帮忙看下:
CString str1;
str1.Format(L"insert into DB_realdrank values(%d,%d,%0.2f,%0.2f,%0.2f,'"+tempname+"')",Iputid,drankid,pose,v1,price);
tempname是CString类型,这个地方报错:
error C2679: binary '+' : no operator found which takes a right-hand operand of type 'const char [3]' (or there is no acceptable conversion)
我把它改为%s插入,没有报错,但是程序运行错误

解决方案 »

  1.   

    http://blog.csdn.net/sailorlyq/archive/2009/03/21/4010773.aspx
      

  2.   

    insert into DB_realdrank values(%d,%d,%0.2f,%0.2f,%0.2f,'"+tempname//这样不能加。tempname + L"insert into DB_realdrank values(%d,%d,%0.2f,%0.2f,%0.2f,'"//这样可以//报的错误是没有重载操作符,没有合适的转换。ExampleThe following example demonstrates the use of CString::operator +.// example for CString::operator +
    CString s1( "abc" );
    CString s2( "def" );
    ASSERT( (s1 + s2 ) == "abcdef" );
    CString s3;
    s3 = CString( "abc" ) + "def" ; // Correct
    s3 = "abc" + "def"; 
    // Wrong! The first argument must be a CString.
      

  3.   

    恩,谢谢楼上,你说的是两个CString的相加,我的问题是向数据库中插入CString变量
      

  4.   

    str1.Format(L"insert into DB_realdrank values(%d,%d,%0.2f,%0.2f,%0.2f,'%s')",Iputid,drankid,pose,v1,price, tempname);
    试试这样。
      

  5.   


    CString str1(_T(""));
    str1.Format(_T("insert into DB_realdrank values(%d,%d,%0.2f,%0.2f,%0.2f,\'%s\')"), Iputid,drankid,pose,v1,price,tempname);
    AfxMessageBox(str1);