• c#调用带有自定义表结构的存储过程


    1、新建自定义表结构

    注意字段的顺序要一致 类型要一样 不然会出错 

    CREATE TYPE [dbo].[HBForHBGHDR] AS TABLE(
    [序号] [int] NULL,
    [客户编号] [varchar](15) NULL
    )
    GO
    

      

    2、建立存储过程

    alter PROCEDURE UP_DRGHHB
      @HBList HBForHBGHDR readonly,
      @returnCode varchar(10) output,
      @returnMsg varchar(50) output
    AS
    BEGIN
    	-- SET NOCOUNT ON added to prevent extra result sets from
    	-- interfering with SELECT statements.
    	SET NOCOUNT ON;
       declare @rowcount int
       set @returnCode=1
       select @rowcount=count(1) from @HBList
       --set @returnMsg=(select top 1 [客户编号] from @HBList)
       update jc_hb set yl5=1 where khbh in(select [客户编号] from @HBList)
       set @returnMsg='总共提交条数:'+convert(varchar(10),@rowcount)+',修改成功:'+ convert(varchar(10),@@rowcount)+'条'
    END
    GO
    

     3、调用存储过程

     string returnCode = string.Empty;
                string returnMsg = string.Empty;
                SqlParameter[] paras = new SqlParameter[]{
                    new SqlParameter("@returnCode",returnCode),
                    new SqlParameter("@returnMsg",returnMsg),
                    new SqlParameter("@HBList",dt)
                    };
                paras[0].Direction = ParameterDirection.Output;
                paras[1].Direction = ParameterDirection.Output;
                paras[1].Size = 50;
                paras[2].TypeName = "HBForHBGHDR";
    
                DataSet ds = DbHelperSQL.RunProcedure("[UP_DRGHHB]", paras, "tb1");
                returnMsg = paras[1].Value.ToString();
                returnCode = paras[0].Value.ToString();
                if (returnCode != "1")
                {
                    this.lblError.Text = "批量插入数据失败:" + returnMsg;
                }
                else
                    this.lblError.Text = "批量插入数据成功:" + returnMsg;
    

      

     

  • 相关阅读:
    程序员如何制定自己的一份年度计划
    【Spring入门系列】篇3:再探IOC
    【Spring入门系列】篇2:SpringIOC入门
    【Spring入门系列】篇1:Spring简介
    适配器模式
    java编程思想之正则表达式
    代理模式
    建造者模式
    抽象工厂模式
    工厂方法模式
  • 原文地址:https://www.cnblogs.com/chenqingbin/p/11009877.html
Copyright © 2020-2023  润新知