数据库:SQL SERVER2000
环境:D7 UPDATE1;
控件:AdoStoreProc问题:执行一个存储过程,会返回一个结果集和一个返回值。使用AdoStoreProc.Open或AdoStoreProc.execproc,都只能返回结果集,无法返回 返回值。
1.存储过程没有问题,在sql的查询分析器中调试可以返回结果集和返回值
2.代码中已正确定义有关参数,如下:    with SPGetId do
    begin
      Close;
      ProcedureName := 'sp_pageview';
      Parameters.Clear;
      Parameters.Refresh;      Parameters.ParamByName('@tbname').Value := 'Tb_clientInfo';
      parameters.ParamByName('@FieldKey').Value := 'ClientId';
      parameters.ParamByName('@PageCurrent').Value := Pagecount;
      parameters.ParamByName('@PageSize').Value := 5;
      parameters.ParamByName('@FieldShow').Value := '*';
      parameters.ParamByName('@FieldOrder').Value := 'ClientId desc';
      parameters.ParamByName('@Where').Value := '';
      parameters.ParamByName('@PageCount').Value := -1;
      Open;
      MaxPageCount := SPGetId.Parameters.PARAMBYNAME('@PageCount').Value;
    end;    返回值@PageCount无法有效取回    请问有何解决方法!

解决方案 »

  1.   

    可以通过NextRecordset返回第2个结果集吗?
      

  2.   

    @PageCount 看看在结果集合中一起带出。我们经常用 select 'T',.....这样的来表示存储过程是否内部处理成功。
      

  3.   

    是不是D7的问题?
    我在D6下测试没有问题。  with ADOStoredProc1 do
      begin
        Close;
        ProcedureName := 'p_test';
        Parameters.Clear;
        Parameters.Refresh;    Parameters.ParamByName('@a').Value := 12;
        Parameters.ParamByName('@b').Value := 0;
        Open;
        ShowMessage(vartostr(Parameters.PARAMBYNAME('@b').Value));
      end;create proc p_test
      @a int,
      @b int output
    as
    begin
      select @b=@a*@a
      select @a,@b
    end
      

  4.   

    parameters.clear;也该删除,如果clear了,你需要一个个add上去,其实不用clear,只要
    parameters.refresh就会动态刷新了。
    //一般的输入参数,不用设置direction,只有输出参数才需要。//输出参数要赋值,随便给一个合语法的值,在存储过程执行后手动取得输出参数的值
    sp_allmoney.Connection := con_SystemLog;
      sp_allmoney.Close;
      sp_allmoney.ProcedureName := 'PrGm_GetCash';
      sp_allmoney.Parameters.Refresh;
      sp_allmoney.Parameters.ParamByName('@inbSilverCloudNet').Direction := pdoutput;
      sp_allmoney.Parameters.ParamByName('@inbSilverCloudNet').Value := inbSilverCloudNet;  sp_allmoney.Parameters.ParamByName('@inb99Bill').Direction := pdoutput;
      sp_allmoney.Parameters.ParamByName('@inb99Bill').Value := inb99Bill;  sp_allmoney.Parameters.ParamByName('@inbSilver168').Direction := pdoutput;
      sp_allmoney.Parameters.ParamByName('@inbSilver168').Value := inbSilver168;  sp_allmoney.Parameters.ParamByName('@inbSilverSMS').Direction := pdoutput;
      sp_allmoney.Parameters.ParamByName('@inbSilverSMS').Value := inbSilverSMS;  sp_allmoney.Parameters.ParamByName('@inySort').Value := UUserLogin.lSort;
      sp_allmoney.ExecProc;
      
    if sp_allmoney.parameters.parambyname('@Return_Value').value=1 then//这里取得返回结果
    begin
      FlatEdit1.Text := sp_allmoney.Parameters.ParamByName('@inbSilverSMS').Value;
      FlatEdit2.Text := sp_allmoney.Parameters.ParamByName('@inbSilver168').Value;
      FlatEdit3.Text := sp_allmoney.Parameters.ParamByName('@inbSilverCloudNet').Value;
      FlatEdit4.Text := sp_allmoney.Parameters.ParamByName('@inb99Bill').Value;
    end;
      

  5.   

    AdoStoreProc.execproc//用于没有返回集的时候
    Open;//用于有返回集
    两个不能通用的
      

  6.   

    你存储过程里面怎么写的输出参数,如果对参数输出是用
    set @param = ... 或者 select @param = ... 是不行的,
    必须是在定义参数的时候 定义 output 参数
      

  7.   

    select的话,一般加别名作为字段名,从数据集合取数据方便select @param [参数1]这样根据类型用parambyname('')或者parameValue['']可以取到
      

  8.   

    谢谢各位,问题已经解决调试方式为:直接在AdostoredPrdc控件里面设置所有参数,并赋值,然后令控件的active为true。可以看到返回值。比较奇怪的是,如果输出参数@PageCount设置为任意值的话,那么返回值必定是所设定的值
    只能将其设置为Null,否则无法得到正确值。windindance提到d6下面测试没有问题,这个我还没有测试。分迟一点结给大家,谢谢