String sql="insert into content values((select title from content 
where id=rid),'"+istatement+"','"+iname+"',getdate(),"+sid+")";
------^^^^^^^哪个是变量?

解决方案 »

  1.   

    多谢!rid是从上一页传过来的参数,sid也是(sid不是问题),主要想把这个id对应的title查出来,可你的方法不行啊!在sql 查询分析器中报错说“在此上下文中不允许使用子查询。只允许使用标量表达式。”??为什麽?
      

  2.   

    ssql="insert into content values((select title from content 
    where id="+rid+"),'"+istatement+"','"+iname+"',getdate(),"+sid+")"
      

  3.   

    但是我在sql 查询分析器中测试时:把句子改成ssql="insert into content values((select title from content 
    where id=4),'hello','iname',getdate(),6)"都报同样的错!
      

  4.   

    在查询分析器中,字符串不能用“,而只能用‘,如果你values后的括号中为内容的话,应该用‘号引起来,注意配对。如果是通过select 查询其他表的记录插入,必须将values去掉。
      

  5.   

    String sql="insert into content (你把列名写出来呢?) values((select title from content 
    where id=rid),'"+istatement+"','"+iname+"',getdate(),"+sid+")";
      

  6.   

    ssql="insert content select title,'hello','iname',getdate(),6 from content 
    where id=4"
      

  7.   

    ssql="insert into content values((select title from content 
    where id="+rid+"),'"+istatement+"','"+iname+"',getdate(),"+sid+")"