str=“update qindan set xiaofei=“+str1+”where sijian=”+strtime;
db。excutesql(str);//Cdatabase db;
执行后提示错误:
语法错误(操作符丢失)在查询表达式'****'中(这里的****是变量str1中的内容)

解决方案 »

  1.   

    str.Format("update qindan set xiaofei='%s' where sijian='%s'", str1, strtime);
    //可以将你的SQL语句先在数据库的查询中执行一下试试
      

  2.   

    试试
    update qindan set xiaofei="+str1+" where sijian='"+strtime+"'";
      

  3.   

    试试
    update qindan set xiaofei="+str1+" where sijian='"+strtime+"'";
      

  4.   

    你先格式化你的str
    str.Format("update qindan set xiaofei='%s' where sijian='%s'", str1, strtime);
    至于你+str1+这种操作完全可以在外部通过设定一个变量来实现,在SQL语句里面最好不要这样写
    比如:
    CString Strtemp;
    //用Strtemp来完成操作
    然后 把Strtemp 的值付给Strl
      

  5.   

    再问一下:如果表中有一项是时间类型,那么在程序中可以把cstring的变量值存入表中这项吗?
      

  6.   

    当然要看一下数据库的类型,如ORACLE,SYBASE,SQL seriver;
    各种数据库的时间类型格式不一样的。
      

  7.   

    在用这种方法写SQL语句的时候,要注意空格,比如
    str=“update qindan set xiaofei=“+str1+”where sijian=”+strtime;最后的SQL语句是update qindan set xiaofei=XXXwhere sijian=XXXX
    where 于前面的字符连在了一起
      

  8.   

    不同类型数据库的时间转换:
    Access:
    "select * from t_abc where col_time=#2003-09-24#"SQL Server:
    "select * from t_abc where col_time=convert(datetime,'2003-09-24',2)"Oracle:"select * from t_abc where col_time=to_date('2003-09-24')"