我想用delphi中的TADOStoredProcedure控件来获取存储过程的返回值,却报错。
存储过程aaa
CREATE procedure aaa
 @cydid varchar(50),
@sjdw varchar(50) output,
@cmpc varchar(50) output
 as    declare @use varchar(50),
@use2 varchar(50)
  begin
    select @use=sjdw, @use2=cpmc  from jbxx where cydid=@cydid
  select @sjdw=@use
 select @cmpc=@use2
        
   end
GOdelphi代码:
with sp1 do//sp1是TADOStoredProcedure控件
   begin
     Connection:=con1;
    // Close;
     ProcedureName:='aaa';
     with Parameters do
       begin
         Clear;
         Refresh;
         CreateParameter('cydid',ftString,pdInput,50,null);
         CreateParameter('sjdw',ftString,pdOutput,50,null);
         CreateParameter('cmpc',ftString,pdOutput,50,null);
         end;
        Parameters[0].Value:=Trim(edt1.Text);
         Prepared;
          ExecProc;
         try
           edt2.Text:=Parameters.parambyname('sjdw').Value;
           edt3.Text:=Parameters.parambyname('cmpc').Value;
           except
             ShowMessage('执行错误!');
             end;     end;运行后报“为过程或函数aaa指定的参数过多。

解决方案 »

  1.   

    将这个 <存储过程aaa >在数据库中运行看看有没有
    错误,若有的话,就将这个<存储过程aaa >写到一个
    文本文件中再引用试试,若没有错误的话,就是你在
    DELPHI中的语句可能有问题>>>>>>>>>>>
      

  2.   


    Refresh 之后,無需再創建參數,直接訪問即可
     //       CreateParameter('cydid',ftString,pdInput,50,null); 
     //       CreateParameter('sjdw',ftString,pdOutput,50,null); 
     //       CreateParameter('cmpc',ftString,pdOutput,50,null); 
      

  3.   

    这样修改后,报“过程aaa需要提供参数'@cydid',但未提供该参数。
      

  4.   


    Refresh 之前,先prepared:= True
      

  5.   

    另外,參數名訪問,應該是這樣Parameters.parambyname('@cmpc').Value,要加一個@
      

  6.   

    自己解决了,这一段
    with Parameters do 
          begin 
            Clear; 
            Refresh; 
            CreateParameter('cydid',ftString,pdInput,50,null); 
            CreateParameter('sjdw',ftString,pdOutput,50,null); 
            CreateParameter('cmpc',ftString,pdOutput,50,null); 
            end; 
    把Refresh注释掉就好了。但还是给分吧。