CREATE proc TotalMoney
@SupplierName varchar(15),@ShouldPay  money output,@SolidPay money output,@NoPay money output
as 
select @ShouldPay=SUM(应收金额), @SolidPay=SUM(已收金额),@NoPay=SUM(应收金额)-SUM(已收金额) from 入库信息 where 供应商名称 like @SupplierName
set @ShouldPay=@ShouldPay  
set @SolidPay=@SolidPay  
set @NoPay=@NoPay
RETURN @@ROWCOUNT
GO我想从存储过程返回 应收金额,已收金额,未付金额 不知这样的存储过程是否正确!!!
再就是在C#或VB.NET中调用上面的存储过程的返回值是怎么实现的,希望大家帮帮我,我卡在这里已经两三天了,无法完成这个就无法完成任务呀!这个是从Msdn中搜索到的:改了一些东西,能返回值,但我想要的不是这些:存储过程:
CREATE PROCEDURE InsertCategory
  @CategoryName nchar(15),
  @Identity int OUT
AS
INSERT INTO Categories (CategoryName) VALUES(@CategoryName)
SET @Identity = @@Identity
RETURN @@ROWCOUNTC#中的调用代码:
SqlConnection nwindConn = new SqlConnection("Data Source=goodview;Integrated Security=SSPI;" +
"Initial Catalog=northwind"); SqlDataAdapter catDA = new SqlDataAdapter("SELECT CategoryID, CategoryName FROM Categories", nwindConn); catDA.InsertCommand = new SqlCommand("InsertCategory", nwindConn);
catDA.InsertCommand.CommandType = CommandType.StoredProcedure; SqlParameter myParm = catDA.InsertCommand.Parameters.Add("@RowCount", SqlDbType.Int);
myParm.Direction = ParameterDirection.ReturnValue; catDA.InsertCommand.Parameters.Add("@CategoryName", SqlDbType.NChar, 15, "CategoryName"); myParm = catDA.InsertCommand.Parameters.Add("@Identity", SqlDbType.Int, 0, "CategoryID");
myParm.Direction = ParameterDirection.Output; DataSet catDS = new DataSet();
catDA.Fill(catDS, "Categories"); DataRow newRow = catDS.Tables["Categories"].NewRow();
newRow["CategoryName"] = "New Category";
catDS.Tables["Categories"].Rows.Add(newRow); catDA.Update(catDS, "Categories"); Int32 rowCount = (Int32)catDA.InsertCommand.Parameters["@RowCount"].Value;
textBox1.Text=rowCount.ToString();
int inText=(int)catDA.InsertCommand.Parameters["@Identity"].Value;
textBox2.Text=inText.ToString();
string strName=(string)catDA.InsertCommand.Parameters["@CategoryName"].Value;
                textBox3.Text=strName.ToString();

解决方案 »

  1.   


    执行后,
    xxxx=xxxcommand.Parameters["aaa"].value 大致如此
      

  2.   

    select @ShouldPay=SUM(应收金额), @SolidPay=SUM(已收金额),@NoPay=SUM(应收金额)-SUM(已收金额) from 入库信息 where 供应商名称 like @SupplierName
    set @ShouldPay=@ShouldPay  
    set @SolidPay=@SolidPay  
    set @NoPay=@NoPay 
    不要后面这三个set
      

  3.   

    我一般直接在存储过程中sql语句,很少用变量,你是不是把问题想的太复杂了
      

  4.   

    没有呀!我只是想在存储过程中负值,然后在VB.NET or C# 中获得值.
      

  5.   

    TO bumm  你给的网站里,只是有插入数据时返回受影响的行和ID,我上面的例子已有,我只是想要返回汇总的金额,但是C#中的参数都要对应存储过程中的参数,好像无法有返回值呀!!不知哪位高手帮改一下存储过程,再给点C#或VB.NET代码提示??再次表示感谢!!!
      

  6.   

    CREATE proc TotalMoney
    @SupplierName varchar(15),@ShouldPay  money output,@SolidPay money output,@NoPay money output
    as 
    select @ShouldPay=SUM(应收金额), @SolidPay=SUM(已收金额),@NoPay=SUM(应收金额)-SUM(已收金额) from 入库信息 where 供应商名称 like @SupplierName
    GO 
    这样就差不多了,带参数的like子句你注意一下,我忘了怎么写合适了。
    用的时候也是先创建ParameterDirection.Output形式的参数,
    ExecuteNoQuery后再取参数的Value
      

  7.   

    怎么不用strong typed dataset?向导会自动生成存储过程的调用代码