有这么一段代码:
dm.sqlllhead.Close;
dm.sqlllhead.SQL.Clear;
if a='2' then
dm.sqlllhead.SQL.Add('select  a.llcode,a.llbm,a.bwlvs,a.isjg,a.jgbm,a.toolr,a.kostl,a.yt ,a.bz,a.llr,
b.spr from llhead a left join spjl b on a.llcode=b.llcode  where a.llcode=:llcode and  b.type=''Y'' and appstatus=''同意'')
else
dm.sqlllhead.SQL.Add('select a.llcode,a.llbm,a.bwlvs,a.isjg,a.jgbm,a.toolr,a.kostl,a.yt ,a.bz,a.llr,b.spr from llhead a left join spjl b on a.llcode=b.llcode  where a.llcode=:llcode');
dm.sqlllhead.Parameters.ParamByName('llcode').Value:=b;
dm.sqlllhead.Open;
a和b都是有具体值的,但是当程序运行第一个select时,程序正常,当运行第二个select时,出现一个出错提示“an unknow error has occures”!
第一个select语句与第二个select语句只相差后面的两个条件有或者没有!
不知错在哪里?
请高手们帮忙!谢谢

解决方案 »

  1.   

    else
    begin    -----!!!
    dm.sqlllhead.SQL.Add('select a.llcode,a.llbm,a.bwlvs,a.isjg,a.jgbm,a.toolr,a.kostl,a.yt ,a.bz,a.llr,b.spr from llhead a left join spjl b on a.llcode=b.llcode  where a.llcode=:llcode');
    dm.sqlllhead.Parameters.ParamByName('llcode').Value:=b;
    end;     -----!!!
    差个begin end;
      

  2.   

    如果连接用的ADO,则第二种方法
    dm.sqlllhead.Parameters.ParamByName('llcode').Value:=b;
    不支持,BDE可以。
    改为:
    dm.sqlllhead.SQL.Add('select a.llcode,a.llbm,a.bwlvs,a.isjg,a.jgbm,a.toolr,a.kostl,a.yt ,a.bz,a.llr,b.spr from llhead a left join spjl b on a.llcode=b.llcode  where a.llcode='+#39+yourParamValue+#39);
      

  3.   

    不是啊!
    else后面就一条select语句;
    这条语句:dm.sqlllhead.Parameters.ParamByName('llcode').Value:=b;不管在什么状态下都要运行的,不需要begin...end!
      

  4.   

    prepared;  
      open;
      append(edit);
      dm.sqlllhead.Parameters.ParamByName('llcode').Value:=b;
      post;
      

  5.   

    blueer:
    你的方法我也试过,也是出现同样的错误。
    现在更奇怪的是:我在DELPHI环境中运行会出现错误,如果直接运行.exe文件则没有出现错误!搞不懂!
      

  6.   

    哦 看错了
    二楼的,ADO支持参数的
      

  7.   

    你没有说出现什么错误提示,你试试,在第二个SELECT前加上SQL.CLOSE;SQL.CLEAR;关闭一次,清除一次。另你应把第二个SELECT与第一个换一下位子,如果仍然是第二个出现问题,那就是没有关闭和清除。