sql 通过存储过程和自定义类型批量新增数据
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了sql 通过存储过程和自定义类型批量新增数据,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含1957字,纯文字阅读大概需要3分钟。
内容图文
![sql 通过存储过程和自定义类型批量新增数据](/upload/InfoBanner/zyjiaocheng/449/fede4b7d1da44265884e0b8969ee8fde.jpg)
1,建立存储过程
create PROCEDURE [dbo].[p_Company_Insert] @CompanyCollection [CompanyTableType] READONLY AS INSERT INTO tb_Company ( [cpID] ,[cpHiID] ,[cpBuySellTypeID] ,[cpName] ,[cpShortName] ,[cpIndustry] ,[cpSell] ,[cpBuy] ,[cpAddressID] ,[cpAddress] ,[cpPost] ,[cpTel] ) SELECT oc.[cpID] ,oc.[cpHiID] ,oc.[cpBuySellTypeID] ,oc.[cpName] ,oc.[cpShortName] ,oc.[cpIndustry] ,oc.[cpSell] ,oc.[cpBuy] ,oc.[cpAddressID] ,oc.[cpAddress] ,oc.[cpPost] ,oc.[cpTel] FROM @CompanyCollection AS oc; GO
2,建立相对应的数据类型
/****** Object: UserDefinedTableType [dbo].[CompanyTableType] Script Date: 07/04/2014 10:20:51 ******/ CREATE TYPE [dbo].[CompanyTableType] AS TABLE( [cpID] [int] NOT NULL, [cpHiID] [int] NULL, [cpBuySellTypeID] [nvarchar](200) NULL, [cpName] [nvarchar](200) NOT NULL, [cpShortName] [nvarchar](200) NULL, [cpIndustry] [nvarchar](300) NULL, [cpSell] [nvarchar](200) NULL, [cpBuy] [nvarchar](200) NULL, [cpAddressID] [int] NOT NULL, [cpAddress] [nvarchar](300) NULL, [cpPost] [nvarchar](100) NULL, [cpTel] [nvarchar](100) NULL, ) GO
3,执行代码
/// <summary> /// 单条添加,将datatable作为参数传进去,返回datatable的自增长编号(调用存储过程) /// </summary> /// <param name="dt"></param> /// <returns></returns> [WebMethod] public DataTable BuySell_Insert(DataTable dt, string token) { CheckLoginedS(token); if (dt.Rows.Count > 0 && dt.Rows != null) { tb_BuySell bs = new tb_BuySell(); DataTable bt = bs.BuySell_Insert(dt); return bt; } else { return null; } } /// <summary> /// 把datatable当参数,批量添加数据库中,返回datatable的新增行 /// </summary> /// <param name="tb"></param> /// <returns></returns> public DataTable BuySell_Insert(DataTable tb) { DataTable dt = null; CMD.CommandText = "p_BuySell_Insert"; CMD.CommandType = CommandType.StoredProcedure; CMD.Parameters.Clear(); CMD.Parameters.AddWithValue("@BuySellCollection", tb); dt = DB.DataTable(CMD); return dt; }
sql 通过存储过程和自定义类型批量新增数据
标签:
本文系统来源:http://www.cnblogs.com/Aamir-Ye/p/4560961.html
内容总结
以上是互联网集市为您收集整理的sql 通过存储过程和自定义类型批量新增数据全部内容,希望文章能够帮你解决sql 通过存储过程和自定义类型批量新增数据所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。