SQL SERVER 2000中的存储过程为:
create proc aa
@X int output
AS
begin
  begin tran
  set XACT_ABORT on
  set ANSI_NULL_DFLT_ON on
  set ANSI_WARNINGS on
  ....
  if @@ERROR<>0 goto Error
  commit tran
  set @X=0
  Error:
  rollback tran
  set @X=1
end 
DELPHI中程序代码如下:
ADOStoredProc1.Close;
ADOStoredProc1.Parameters[0].Value:=3;
ADOStoredProc1.ExecProc;
case ADOStoredProc1.Parameters.ParamByName('X').Value of
0:  showmessage('return 0');
1: showmessage('return 1');
else
   showmessage('return other');
end;
程序运行后出错:‘list index out of bound(0)'
请专家帮忙!

解决方案 »

  1.   

    1、ADOStoredProc1.ExecProc;改为ADOStoredProc1.Open;试试!
    2、用存储过程的Result表示返回值!注意:Goto语句在SQL2000中已经不建议使用了!
      

  2.   

    ADOStoredProc1.Close;
    ADOStoredProc1.ExecProc;
    case ADOStoredProc1.Parameters.ParamByName('X').Value of
    0:  showmessage('return 0');
    1: showmessage('return 1');
    else
       showmessage('return other');
    end;
      

  3.   

    ZIQING:
    你的方法一样出错。
      

  4.   

    ADOStoredProc1.Close;
    DOStoredProc1.Parameters.CreateParameter('x',ftstring,ptoutput,10,null);ADOStoredProc1.ExecProc;
    case ADOStoredProc1.Parameters.ParamByName('X').Value of
    0:  showmessage('return 0');
    1: showmessage('return 1');
    else
       showmessage('return other');
    end;你试试希望你看看帮助!!
      

  5.   

    DOStoredProc1.Parameters.CreateParameter('x',ftstring,ptoutput,10,null);
    X的类型为什么设为ftstring?
      

  6.   

    ADOStoredProc1.Parameters.CreateParameter('x',ftstring,ptoutput,10,null);
    这句运行通不过.
      

  7.   

    1、在ADOProc中设置@X为返回值!
    2、我以前的代码,参考一下:(有点长,大致看一下就知道什么意思了)
    Delphi Code:
      if SysDM.GetSysParam(pkOut_IsUniteRecipe)=1 then//山东省
        begin
          with spRecipeSettl1 do
          begin
            Close;
            ParamByName('@XingMing').AsString:=pnlXm.Caption;
            ParamByName('@ShouKuanBM').AsString:=SysDM.GetUserID;
            ExecProc;
            Case ParamByName('Result').AsInteger of
            0:
            begin
              vErrstr:='更新处方主表失败';
              Result:=vErrstr;
              Exit;
            end;
            1:
            begin
              vErrstr:='更新处方明细表失败';
              Result:=vErrstr;
              Exit;
            end;
            2:
            begin
              vErrstr:='生成发票明细表失败';
              Result:=vErrstr;
              Exit;
            end;
            3:
            begin
              vErrstr:='生成发票主表失败';
              Result:=vErrstr;
              Exit;
            end;
            4:
            begin
              vErrstr:='生成发药状态表失败';
              Result:=vErrstr;
              Exit;
            end;
            5:
            begin
              vErrstr:='更新药房库存失败';
              Result:=vErrstr;
              Exit;
            end;
            -1:
            begin
              vErrstr:='生成单据号失败';
              Result:=vErrstr;
              Exit;
            end;
            -2:
            begin
              vErrstr:='发票已用完';
              Result:=vErrstr;
              Exit;
            end;
          end;
        end;
      end;
      

  8.   

    SQL Script:
    if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[pOut_Chg_RecipeSettl1]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
    drop procedure [dbo].[pOut_Chg_RecipeSettl1]
    GOSET QUOTED_IDENTIFIER OFF 
    GO
    SET ANSI_NULLS ON 
    GO/***********************/
    /*   山东省门诊结帐    */
    /***********************/
    CREATE PROCEDURE pOut_Chg_RecipeSettl1(@XingMing varchar(8),@ShouKuanBM varchar(10))
    AS
    --Assay:
    Set Nocount ondeclare @SerialNo varchar(23),@RiQi varchar(10),@DanJuID varchar(10),@Count int
    declare @YingShouJE Numeric(10,2),@ShiShouJE Numeric(10,2),@RetRound Numeric(10,2),@RetRound2 Numeric(10,2),@YingShouZLJE Numeric(10,2),@ShiShouZLJE Numeric(10,2)
    set @SerialNo=convert(varchar(23),getdate(),121)
    set @RiQi=convert(varchar(10),getdate(),120)
    Begin Tran  
      --删除发票临时打印表
      delete Out_TempPrintInvoice where ShouKuanYBM=@ShouKuanBM
      if @@Error<>0
      begin
        RollBack Tran
        Return 12 
      end 
    --Assay:
    --  Update Out_Recipe Set JieSuanBZ=1 where (convert(varchar(10),JiuZhenID)+convert(varchar(10),ChuFangLH)) in
    --  (select convert(varchar(10),JiuZhenID)+convert(varchar(10),ChuFangBM) from Out_TempRecipeNo where RenYuanBM=@ShouKuanBM)
    update Out_Recipe
    set JieSuanBZ=1
    from Out_Recipe a,Out_TempRecipeNo b
    where a.JiuZhenID=b.JiuZhenID and a.ChuFangLH=b.ChuFangBM and b.RenYuanBM=@ShouKuanBM  if @@Error<>0 
      begin
        RollBack Tran
        Return 0--更新处方主表
      end
      

  9.   

    declare Out_Assay Cursor
      for 
      select JiuZhenID,ChuFangBM from Out_TempRecipeNo where RenYuanBM=@ShouKuanBM
      Open Out_Assay
      Declare @JiuZhenID2 int,@ChuFangHao2 int
      Fetch Next from Out_Assay into @JiuZhenID2,@ChuFangHao2
      while (@@Fetch_Status=0)
      begin
        exec pDoc_UpDateAssayOrExamineZT @JiuZhenID2,@ChuFangHao2,2
        if @@Error<>0
        begin
          Close Out_Assay
          Deallocate Out_Assay
          RollBack Tran
          Return 0 --更新检验表错误
        end
        Fetch Next from Out_Assay into @JiuZhenID2,@ChuFangHao2
      end  
      Close Out_Assay
      Deallocate Out_Assay
      
      declare Out_Inv Cursor
      for
      select distinct JiuZhenID from Out_TempRecipeNo where RenYuanBM=@ShouKuanBM
      open Out_Inv
      declare @JiuZhenID int
      Fetch Next from Out_Inv into @JiuZhenID
      while (@@Fetch_Status=0)
      begin
        set @Count=0
        set @YingShouJE=0.00
        set @ShiShouJE=0.00
        set @YingShouZLJE=0.00
        set @ShiShouZLJE=0.00
        declare Out_Invo Cursor
        for 
        select HeSuanBM,Sum(JinE),Sum(ZiLiJE) from Out_RecipeDetail where JiuZhenID=@JiuZhenID and ChuFangLH 
        in (select ChuFangBM from Out_TempRecipeNo where JiuZhenID=@JiuZhenID and RenYuanBM=@ShouKuanBM) 
        Group By HeSuanBM
        order by convert(int,HeSuanBM)
        open Out_Invo
        declare @HeSuanBM varchar(5),@JinE Numeric(10,2),@ZiLiJE Numeric(10,2)
        Fetch Next from Out_Invo into @HeSuanBM,@JinE,@ZiLiJE
        while (@@Fetch_Status=0)
        begin
          exec @DanJuID=pSys_PreGetBill @ShouKuanBM,1
          if @@Error<>0
          begin
            Close Out_Invo
            Deallocate Out_Invo
            Close Out_Inv
            Deallocate Out_Inv
            RollBack Tran
            Return -1--生成单据号错误
          end
          if @DanJuID=-1 
          begin
            Close Out_Invo
            Deallocate Out_Invo
            Close Out_Inv
            Deallocate Out_Inv
            RollBack Tran
            Return -2--单据已用完
          end
          set @Count=@Count+1
          update Out_RecipeDetail Set DanJuID=@DanJuID where JiuZhenID=@JiuZhenID and ChuFangLH 
             in (select ChuFangBM from Out_TempRecipeNo where JiuZhenID=@JiuZhenID and RenYuanBM=@ShouKuanBM)  
              and HeSuanBM=@HeSuanBM
          if @@Error<>0
          begin
            Close Out_Invo
            Deallocate Out_Invo
            Close Out_Inv
            Deallocate Out_Inv
            RollBack Tran
            Return 1--更新处方明细表
          end
      

  10.   

    我在ADOSTOREDPROC1的PARAMETERS的属性中看到了两个变量:@RETURN_VALUE和@X,那在程序中如何获得这两个变量的值?
      

  11.   

    OPEN是用来有返回值的执行,EXECSQL是代表象INSERT,UPDATE等的执行