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 Studio 解决方法No JVM installation found. Please install a 64-bit JDK.
————————— Error launching Android Studio ————————— No JVM installation found. Please install a 64-bi ...
- watch命令详解(linux)
watch命令详解(linux) 在维护系统时经常需要实时查看系统的运行情况,比如实时的系统连接数之类的.在linux可以通过watch命令,实时监控每一条命令执行的结果动态变化. ...
- Python 标识符
Python 标识符 在python里,标识符有字母.数字.下划线组成. 在python中,所有标识符可以包括英文.数字以及下划线(_),但不能以数字开头. python中的标识符是区分大小写的. 以 ...
- 普通内存、ECC内存和REG ECC内存有什么不同
都知道,在INTEL平台,北桥负责与CPU的联系,并控制内存.AGP.PCI数据在北桥内部传输.基本上只要主板芯片组确定,那么其支持的内存类型也就确定了. INTEL芯片组划分的很清楚,865PE属于 ...
- CCNP路由实验(2) -- OSPF
OSPF作为一种内部网关协议(IGP),用于在同一个AS中的路由器之间交换路由信息.OSPF的特性如下:1.可适应大规模网络2.收敛速度快3.无路由环路4.支持VLSM和CIDR5.支持等价路由6.支 ...
- VC++深入详解-第五章学习心得
这一章节主要讲解了文本相关的一些编程 插入符的使用 CreateSolidCaret(100,200);//插入符的宽度和高度 ShowCaret(); 插入符的一般使用方法 int CTestVie ...
- 自己的第一个android应用(天气)
主界面代码 package com.example.weather; import android.os.Bundle; import android.app.Activity; import and ...
- Linux系统源码安装过程中的prefix选项
在linux和unix环境中,源码安装是最常用的软件安装方式,一些软件除了提供源码外,也提供各种发行版的二进制安装包(如基于redhat包管理工具的rpm包),但强烈建议使用源码安装方式.原因是:(1 ...
- zoj 1081 (改进的弧长算法)(转)
看到网上除了射线法,很长一段代码之外,看到了一个很简单的算法解决这个问题,特意转了过来 /* 这个算法是源自<计算机图形学基础教程>(孙家广,清华大学出版社),在该书 的48-49页,名字 ...
- DataSet中取值(转)
1 DataSet.Table[0].Rows[ i ][ j ] 其中i 代表第 i 行数, j 代表第 j 列数 2 DataSet.Table[0].Rows[ i ].ItemArray[ j ...