日期:2014-05-17  浏览次数:21007 次

用C#如何执行存储过程,并带参数呢?帮我写一下代码,谢谢!!1
C# code


SqlParameter[] prams ={
                                                 this.BeylandSoft1.MakeInParam("@GHDWBM",SqlDbType.VarChar,50,a1),
                                                 this.BeylandSoft1.MakeInParam("@RKLXBM",SqlDbType.VarChar,50,a2),
                                                 this.BeylandSoft1.MakeInParam("@WZXXBM",SqlDbType.VarChar,50,a3),
                                                 this.BeylandSoft1.MakeInParam("@SL",SqlDbType.VarChar,50,a4),
                                                 this.BeylandSoft1.MakeInParam("@DJ",SqlDbType.VarChar,50,a5),
                                                 this.BeylandSoft1.MakeInParam("@SCRQSJ",SqlDbType.VarChar,50,a6),
                                                 this.BeylandSoft1.MakeInParam("@CPDQSJ",SqlDbType.VarChar,50,a7),
                                                 this.BeylandSoft1.MakeInParam("@XHBM",SqlDbType.VarChar,50,a8),
                                                 this.BeylandSoft1.MakeInParam("@PHBM",SqlDbType.VarChar,50,a9),
                                                 this.BeylandSoft1.MakeInParam("@JCDWBM",SqlDbType.VarChar,50,a10),
                                                 this.BeylandSoft1.MakeInParam("@YHBM",SqlDbType.VarChar,50,a11),
                                                 this.BeylandSoft1.MakeInParam("@BZ",SqlDbType.VarChar,50,a12),
                                             };
            this.BeylandSoft1.ExeSQL_RunProcedure("PR_KF_YBWZYSD_001", prams);




SQL code

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

ALTER PROCEDURE [dbo].[PR_KF_YBWZYSD_001]
@P_GHDWBM       varchar(50),
@P_RKLXBM        varchar(50),
@P_WZXXBM     varchar(50),
@P_SL     varchar(50),
@P_DJ     varchar(50),
@P_SCRQSJ     varchar(50),
@P_CPDQSJ     varchar(50),
@P_XHBM     varchar(50),
@P_PHBM     varchar(50),
@P_JCDWBM     varchar(50),
@P_YHBM     varchar(50),
@P_BZ     varchar(50),
@ReturnID    varchar(5) OUTPUT

AS
Declare   @V_SL           varchar(50)
Declare   @T_SL           decimal(18,3)
Declare   @T_DJ           decimal(18,2)
Declare   @T_JE           decimal(18,2)
Declare   @P_JE           varchar(50)

Declare   @V_YBWZMX_XLH   bigint
Declare   @V_YBWZKC_XLH           bigint
Declare   @sql           varchar(2000)
Declare   @V_SJ           varchar(50)
Declare   @V_ZERO          varchar(50)

Declare   @P_YBWZMX_XLH   varchar(50)
Declare   @P_YBWZKC_XLH    varchar(50)


/*物资入库与入库冲销用的是这两个存储过程PR_KF_YBWZYSDMX_GC_01,PR_KF_YBWZYSDMX_02*/
/*这两个过程没有用上PR_KF_YBWZYSDMX_01,PR_KF_YBWZYSDMX_GC_02,*/

Begin Transaction 
        /*转换传入值的数据类型 */
        set @T_SL=CAST(@P_SL AS decimal(18,3)) 
        set @T_DJ=CAST(@P_DJ AS decimal(18,2)) 
        set @T_JE=round((@T_SL*@T_DJ),2);
        set @V_SJ=CONVERT(char(11),getdate(),21);   
        set @V_ZERO='0';
        set @P_JE=CAST(@T_JE AS varchar(50)) 

         /*更新库房数量 @@IDENTITY 取得最近写入表的最大自增量 XLH */
       SELECT @V_YBWZMX_XLH=@@IDENTITY  from KF_YBWZMX;
       SELECT @V_YBWZKC_XLH=@@IDENTITY  from KF_YBWZKC;

       set @P_YBWZMX_XLH=CAST(@V_YBWZMX_XLH AS varchar(50)) 
       set @P_YBWZKC_XLH=CAST(@V_YBWZKC_XLH AS varchar(50)) 

       set @P_SCRQSJ=CONVERT(char(11),@P_SCRQSJ,21);   
       set @P_CPDQSJ=CONVERT(char(11),@P_CPDQSJ,21);   


insert into KF_YBWZMX([GHDWBM],[RKLXBM]  ,[WZXXBM] ,[SL],[DJ],[JE],[SCRQSJ] ,[CPDQSJ]
       ,[XHBM] ,[PHBM],[KC_XLH],[JCDWBM]  ,[YHBM]    ,[CJSJ] ,[XTBZ]   ,[SCBZ]    ,[BZ])values (''+
       @P_GHDWBM+'',''+@P_RKLXBM+'',''+@P_WZXXBM+'',''+@P_SL+'',''+@P_DJ+'',''+@P_JE+'',''+@P