create proc  spFuShouAll
(
@ResultFu int output,
@ResultShou int output,
@Resulta int output,
@ResultFuShou int output,
@ResultFua int output,
@ResultFSC int output
)
AS
Declare  @fu  int,@shou  int,@FristDay datetime,
@LastDay datetime,@result int,@FuShou int,@Fua int, @FSC intselect @FristDay=DATEADD(mm, DATEDIFF(mm,0,getdate()), 0) --取当月的第一天
select @LastDay=DATEADD(ms,-3,DATEADD(mm, DATEDIFF(m,0,getdate())+1, 0))--取当月的最后一天select @fu=sum(money) from payinvoice 
where Datetime between @FristDay and @LastDay  
and Cancellation='0' select @shou=sum(Money) from acceptinvoice  --counteractdate字段为抵扣日期
where (counteractdate is  null or rtrim(ltrim(counteractdate))='' ) --这句表示counteractdate的值为空
where Datetime between @FristDay and @LastDay    --DateTime为收发票日期
and Cancellation='0'  --Cancellation字段是否作废 0表示没有作废select @result=(@fu-@shou)/1.17 
select @FuShou=@fu-@shou
select @Fua=@fu*0.01
select @FSC=(@fu-@shou)-(@fu-@shou)/1.17-@fu*0.01set @ResultFu = @fu --输出收发票总额
set @ResultShou = @shou --输出付发票总额
set @Resulta = @result --输出付发票总额-收发票总额/1.17得到的金额
set @ResultFuShou = @FuShou --输出付发票总额-收发票总额
set @ResultFua = @Fua --输出付发票总额*0.01  应我厂应交的金额
set @ResultFSC = @FSC --输出超出我厂应交的金额数   

print @ResultFu
print @ResultShou
print @Resulta
print @ResultFuShou
print @ResultFua
print @ResultFSC
go在C#要如何调用这个存储过程.
把六个对面的值绑定到
Lab1.Text,Lab2.Text,Lab3.Text,Lab4.Text,Lab5.Text,Lab6.Text,

解决方案 »

  1.   

    SqlConnection conn;
    conn.Open();
    comm = new SqlCommand("spFuShouAll",conn);
    comm.CommandType = CommandType.StoredProcedure;comm.Parameters.Add(new SqlParameter("@ResultFu",SqlDbType.Int,4,ParameterDirection.Output,false,0,0,null,DataRowVersion.Default,null));
    comm.CommandType = CommandType.StoredProcedure;comm.Parameters.Add(new SqlParameter("@ResultShou ",SqlDbType.Int,4,ParameterDirection.Output,false,0,0,null,DataRowVersion.Default,null));
    .....其他几个也是这样就不写了
    comm.ExecuteNonQuery();
    Lab1.Text = comm.Parameters["@ResultFu"].Value.ToString();
    Lab2.Text = comm.Parameters["@ResultFu"].Value.ToString();
    .....其他几个也是这样
      

  2.   

    将参数的Direction设置为OutPut就可以了:
    this.sqlConnection1.Open();
    this.sqlCommand1.Connection =this.sqlConnection1;
    this.sqlCommand1.ExecuteNonQuery();
    this.sqlConnection1.Close();
    MessageBox.Show(this.sqlCommand1.Parameters["@ResultFu"].Value.ToString());
    MessageBox.Show(this.sqlCommand1.Parameters["@ResultFSC"].Value.ToString());
      

  3.   

    不用搞那么多参数的 你那些参数全部都是输出参数 你在你的存储过程里面搞一个临时表不就ok了 然后在你的客户端新建cmd connectino da datatable等对象。一会可以手工了
      

  4.   

    执行完存储过程后直接这样就行了
    Label.Text = comm.Parameters["@ResultFu"].Value.ToString();
    …………
      

  5.   

    用企业库可以返回DATASET或DATAREADER,然后你自己去取数据,绑定到控件TEXT属性上就OK。或者直接读取输出参数
    Database db = DatabaseFactory("instance");
    DBCommandWrapper dbc = db.GetStoredProcCommandWrapper("procedure");
    dbc.AddInParameter("@ID",DbType.String,UserID);输入参数对应存储过程里面的参数
    dbc.AddOutParameter("@params",DbType.String,*);输出参数对应存储过程里面的参数
    DataSet data = db.ExecuteDataSet(dbc);返回一个数据集
    DataReader myReader = db.ExecuteDataReader( dbc );返回DATAREADER
    string newUserID = ( string )dbc.GetParameterValue(params_name);获取输出参数的值
      

  6.   

    正解:这个很简单的在 SP  spFuShouAll 里最后加上一句select @ResultFu as Fu ,@ResultShou as Shou ,@Resulta as ta,@ResultFuShou as FuShou
    ,@ResultFua as Fua ,@ResultFSC as FSc然后用DataReader 去读取就可以了, 根本就不用什么temp table 的
      

  7.   

    返回一个DATASET集,临时表也可以
      

  8.   

    try
    {
    ReplyCe.ConnOpen();
    SqlCommand SqlCommand1=new SqlCommand("spFuShouAll",ReplyCe.SqlConnection1);
    SqlCommand1.CommandType=CommandType.StoredProcedure; SqlParameter Param1=new SqlParameter("@ResultFu",SqlDbType.Int);  //输出参数
    SqlParameter Param2=new SqlParameter("@ResultShou",SqlDbType.Int);  //输出参数
    SqlParameter Param3=new SqlParameter("@Resulta",SqlDbType.Int);  //输出参数
    SqlParameter Param4=new SqlParameter("@ResultFuShou",SqlDbType.Int);  //输出参数
    SqlParameter Param5=new SqlParameter("@ResultFua",SqlDbType.Int);  //输出参数
    SqlParameter Param6=new SqlParameter("@ResultFSC",SqlDbType.Int);  //输出参数
    SqlParameter Param7=new SqlParameter("@ResultSB",SqlDbType.Int);  //输出参数 SqlCommand1.Parameters.Add(Param1);
    SqlCommand1.Parameters.Add(Param2);
    SqlCommand1.Parameters.Add(Param3);
    SqlCommand1.Parameters.Add(Param4);
    SqlCommand1.Parameters.Add(Param5);
    SqlCommand1.Parameters.Add(Param6);
    SqlCommand1.Parameters.Add(Param7);

    Param1.Direction=ParameterDirection.Output;  //输出参数
    Param2.Direction=ParameterDirection.Output;  //输出参数
    Param3.Direction=ParameterDirection.Output;  //输出参数
    Param4.Direction=ParameterDirection.Output;  //输出参数
    Param5.Direction=ParameterDirection.Output;  //输出参数
    Param6.Direction=ParameterDirection.Output;  //输出参数
    Param7.Direction=ParameterDirection.Output;  //输出参数 SqlDataReader reader = SqlCommand1.ExecuteReader();
    if (reader.Read())
    {
    this.TextBox5.Text = reader[0].ToString();
    this.TextBox6.Text = reader[1].ToString();
    this.TextBox7.Text = reader[2].ToString();
    this.TextBox8.Text = reader[3].ToString();
    this.TextBox9.Text = reader[4].ToString();
    this.TextBox10.Text = reader[5].ToString();
    this.TextBox11.Text = reader[6].ToString();
    reader.Close();
    ReplyCe.ConnClose();
    }
    else
    {
    reader.Close();
    ReplyCe.ConnClose();
    Response.Write("<script>alert('参数错误!');history.back();</script>");
    Response.End();
    }
    }
    catch
    {
    Response.Write("<script>alert('参数错误!');history.back();</script>");
    Response.End();
    }