bulk insert data into database with table type .net
1. Create Table type in Sqlserver2008.
CREATE TYPE dbo.WordTable as table
(
[WordText] [nchar]() NULL,
[WordCount] [int] NULL
)
And the target table is:
CREATE TABLE [dbo].[A_WordCount](
[id] [int] IDENTITY(1,1) NOT NULL,
[WordText] [nchar](100) NULL,
[WordCount] [int] NULL
)
2.Create Store Procedure.
ALter PROCEDURE [dbo].[A_Words]
@Word as dbo.WordTable READONLY
AS BEGIN
insert into dbo.A_WordCount(WordCount,WordText)
select w.WordCount,w.WordText from @Word w END
3. First we will create a table. Then we will pass this table to the store procedure.
public static DataTable ConvertToTable(List<WordClass> wordLst)
{
DataTable dt = new DataTable();
dt.Columns.Add("WordText", typeof (string));
dt.Columns.Add("Count", typeof (int)); foreach (var word in wordLst)
{
DataRow row = dt.NewRow();
row["WordText"] = word.WordValue;
row["Count"] = word.Count;
dt.Rows.Add(row);
}
return dt;
}
public static void WriteData(DataTable dtTable)
{
commandText = "dbo.[A_Words]";
SqlConnection con;
try
{
using (con = new SqlConnection(connectionString))
{
SqlCommand cmd = new SqlCommand(commandText, con);
cmd.CommandType = CommandType.StoredProcedure;
cmd.Parameters.Add(new SqlParameter("@Word", SqlDbType.Structured));
cmd.Parameters["@Word"].Value = dtTable;
con.Open();
cmd.ExecuteNonQuery();
con.Close();
}
}
catch (Exception)
{
throw;
} }
bulk insert data into database with table type .net的更多相关文章
- Bulk Insert Data
Bulk Insert Data 命名空间:Oracle.DataAccess.Client 组件:Oracle.DataAccess.dll(2.112.1.0) ODP.NET 版本:ODP.NE ...
- [Oracle] Bulk Insert Data
命名空间:Oracle.DataAccess.Client 组件:Oracle.DataAccess.dll(2.112.1.0) ODP.NET 版本:ODP.NET for .NET Framew ...
- C# .NET - Sql Bulk Insert from multiple delimited Textfile using c#.net
SqlBulkCopy.WriteToServer has 4 overloads:SqlBulkCopy.WriteToServer (DataRow[]) Copies all rows f ...
- Insert data from excel to database
USE ESPA Truncate table dbo.Interface_Customer --Delete the table data but retain the structure exec ...
- 从一个Bug说开去--解决问题的思路,Linked Server, Bulk Insert, DataTable 作为参数传递
声名— 部分内容为杜撰,如有雷同,不胜荣幸! 版权所有,如要引用,请标明出处! 如果打赏,请自便! 1 背景介绍 最近一周在忙一个SQL Server 的Bug,一个简单的Bug,更新两张 ...
- SQL Server Bulk Insert批量数据导入
SQL Server的Bulk Insert语句可以将本地或远程的数据文件批量导入到数据库中,速度非常的快.远程文件必须共享才行,文件路径须使用通用约定(UNC)名称,即"\\服务器名或IP ...
- SQL SERVER – Import CSV File Into SQL Server Using Bulk Insert – Load Comma Delimited File Into SQL Server
CSV stands for Comma Separated Values, sometimes also called Comma Delimited Values. Create TestTabl ...
- [转]Insert, Update, and Delete Destination table with SSIS
本文转自:http://www.rad.pasfu.com/index.php?/archives/150-Insert,-Update,-and-Delete-Destination-table-w ...
- Bulk Insert:将文本数据(csv和txt)导入到数据库中
将文本数据导入到数据库中的方法有很多,将文本格式(csv和txt)导入到SQL Server中,bulk insert是最简单的实现方法 1,bulk insert命令,经过简化如下 BULK INS ...
随机推荐
- Android Sdk 国内镜像下载地址
大连东软信息学院镜像服务器地址:- http://mirrors.neusoft.edu.cn 端口:80北京化工大学镜像服务器地址:- IPv4: http://ubuntu.buct.edu.cn ...
- 【LeetCode题意分析&解答】35. Search Insert Position
Given a sorted array and a target value, return the index if the target is found. If not, return the ...
- pl sql 无法解析指定的连接标识符
使用PLSQL Developer时,“ORA-12154: TNS:无法解析指定的连接标识符”问题的一个解决办法< xmlnamespace prefix ="o" ...
- oracle plsql 64位 32位连接未打开 无法解析各种错终极解决方案
首先取消登陆,进入pl/sql界面-工具-首选项 其次就需要你设置环境变量(加一个ORACLE_HOME和修改原先path里的路径这个不修改也行,主要是让大家知道为什么设置环境变量) 这些设置好,你在 ...
- 在PADS LAYOUT中修改所有元件字体的大小,怎么修改?
1.选中一个字符,Ctrl+Q查看一下属性,是在哪一层. 2.Ctrl+Alt+F(Filter)打开滤波器选项,点Layer,将除字符所在层之外的层全部关掉,即将其前面的"√"去 ...
- 工作学习笔记——GDI泄露检测利器
用.Net写的地图编辑器,最近在一个长时间使用的策划手里频繁挂掉.定位到原因应该是GDI泄露.但在几千行代码里手工寻找泄漏点实在是有些困难,直到在网上找到了这个检测GDI泄露的工具GDILeaks.它 ...
- HDU 5787 K-wolf Number(数位DP)
[题目链接] http://acm.hdu.edu.cn/showproblem.php?pid=5787 [题目大意] 求区间[L,R]内十进制数相邻k位之间不相同的数字的个数. [题解] 很显然的 ...
- Arcgis for javascript不同的状态下自己定义鼠标样式
俗话说:爱美之心.人皆有之. 是的.没错,即使我仅仅是一个做地图的,我也希望自己的地图看起来好看一点. 在本文,给大家讲讲在Arcgis for javascript下怎样自己定义鼠标样式. 首先.说 ...
- 跟我一起学extjs5(19--模块记录的拖放删除、拖放复制新增)
跟我一起学extjs5(19--模块记录的拖放删除.拖放复制新增) 网页其中的拖放(drag-drop)是比較有趣的操作,extjs5中非常好的封装了拖放的动作,也有各种类来支持,可是 ...
- iOS 自定义各类bar的属性
在iOS应用开发中,经常需要为导航栏和标签栏设置相同的主题,一个一个去设置的话,就太麻烦了,可以通过对应用中所有的导航栏和标签栏同意设置背景.字体等属性. 如:创建一个继承自“UINavigation ...