我用SqlDataSource控件调用存储过程,可是无法获取到输出参数的值,我用了两种方法都不行
1、在页面设置
   <asp:ControlParameter ControlID="txtTime" Direction="InputOutput" Name="AccountTime"
                    PropertyName="Text" Type="String" />
                <asp:ControlParameter ControlID="txtYingFuAccounts" Direction="InputOutput" Name="YingFuAccounts"
                    PropertyName="Text" Type="Decimal" />
                <asp:ControlParameter ControlID="txtYiFuAccounts" Direction="InputOutput" Name="YiFuAccounts"
                    PropertyName="Text" Type="Decimal" />
                <asp:ControlParameter ControlID="txtShengYuAccounts" Direction="InputOutput" Name="ShengYuAccounts"
                    PropertyName="Text" Type="Decimal" />2、在Selecting事件中设置
   SqlParameter p1 = new SqlParameter("@AccountTime", SqlDbType.NChar);
        p1.Direction = ParameterDirection.Output;
        e.Command.Parameters.Add(p1);
        SqlParameter p2 = new SqlParameter("@YingFuAccounts", SqlDbType.NChar);
        p2.Direction = ParameterDirection.Output;
        e.Command.Parameters.Add(p2);
        SqlParameter p3 = new SqlParameter("@YiFuAccounts", SqlDbType.NChar);
        p3.Direction = ParameterDirection.Output;
        e.Command.Parameters.Add(p3);
        SqlParameter p4 = new SqlParameter("@ShengYuAccounts", SqlDbType.NChar);
        p4.Direction = ParameterDirection.Output;
        e.Command.Parameters.Add(p4);
我看了一下,返回参数的值都为空,怎么回事啊?

解决方案 »

  1.   

    ALTER PROCEDURE [dbo].[USP_Cost_Shift_Select] 
    -- Add the parameters for the stored procedure here
    @SalerCode nvarchar(50),
        @AccountTime nchar(10) output,
        @YingFuAccounts numeric(10,2) output,
        @YiFuAccounts numeric(10,2) output,
        @ShengYuAccounts numeric(10,2) output
    AS
    BEGIN
    -- SET NOCOUNT ON added to prevent extra result sets from
    -- interfering with SELECT statements.
    SET NOCOUNT ON;    -- Insert statements for procedure here
        Select @AccountTime = left(convert(nvarchar(50), getdate(),120),10),
               @YingFuAccounts = sum(YingFuAccount),
               @YiFuAccounts = (select isnull(sum(ZhiFuAccount),0) From Cost_Shift_Account Where SalerCode = @SalerCode),
               @ShengYuAccounts = (sum(YingFuAccount) - (select isnull(sum(ZhiFuAccount),0) From Cost_Shift_Account Where SalerCode = @SalerCode))
         From Cost_Shift  
         Where SalerCode = @SalerCode
         Group By SalerCode
    END在sqlserver中运行有返回值的呀
      

  2.   

    首先将SqlDataSource绑定到显示数据的控件!!
    设置参数是:
    SqlDataSource1.SelectParameters["SalerCode"].DefaultValue = "xxx";
    ..................