在C#如何调用存储过程中返回多个值

来源:互联网 发布:淘宝上鹅肝罐头 编辑:程序博客网 时间:2024/05/22 01:43

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   int  
   
  select   @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.01  
   
  set   @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

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();  
  .....其他几个也是这样   
    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();  
  .....其他几个也是这样   
   

原创粉丝点击