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的更多相关文章

  1. Bulk Insert Data

    Bulk Insert Data 命名空间:Oracle.DataAccess.Client 组件:Oracle.DataAccess.dll(2.112.1.0) ODP.NET 版本:ODP.NE ...

  2. [Oracle] Bulk Insert Data

    命名空间:Oracle.DataAccess.Client 组件:Oracle.DataAccess.dll(2.112.1.0) ODP.NET 版本:ODP.NET for .NET Framew ...

  3. C# .NET - Sql Bulk Insert from multiple delimited Textfile using c#.net

    SqlBulkCopy.WriteToServer has 4 overloads:SqlBulkCopy.WriteToServer (DataRow[])    Copies all rows f ...

  4. Insert data from excel to database

    USE ESPA Truncate table dbo.Interface_Customer --Delete the table data but retain the structure exec ...

  5. 从一个Bug说开去--解决问题的思路,Linked Server, Bulk Insert, DataTable 作为参数传递

    声名— 部分内容为杜撰,如有雷同,不胜荣幸! 版权所有,如要引用,请标明出处! 如果打赏,请自便! 1       背景介绍 最近一周在忙一个SQL Server 的Bug,一个简单的Bug,更新两张 ...

  6. SQL Server Bulk Insert批量数据导入

    SQL Server的Bulk Insert语句可以将本地或远程的数据文件批量导入到数据库中,速度非常的快.远程文件必须共享才行,文件路径须使用通用约定(UNC)名称,即"\\服务器名或IP ...

  7. 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 ...

  8. [转]Insert, Update, and Delete Destination table with SSIS

    本文转自:http://www.rad.pasfu.com/index.php?/archives/150-Insert,-Update,-and-Delete-Destination-table-w ...

  9. Bulk Insert:将文本数据(csv和txt)导入到数据库中

    将文本数据导入到数据库中的方法有很多,将文本格式(csv和txt)导入到SQL Server中,bulk insert是最简单的实现方法 1,bulk insert命令,经过简化如下 BULK INS ...

随机推荐

  1. javascript 修改css样式

    abc.css CSS code .class1     {    width:10px;    background-color: red;    } HTML code <!DOCTYPE ...

  2. phome_enewsclass 数据表字段解释(栏目主表)

    字段名 类型 解释 附加说明 classid smallint(6) 栏目ID   bclassid smallint(6) 父栏目ID   classname varchar(50) 栏目名称   ...

  3. 转: Apache SSI详解及应用

    转: Apache SSI详解及应用 什么是 SSI? SSI(Server Side Includes),是嵌套在 HTML 网页中的指示语句,由后台服务器进行代码的解释计算.使用 SSI 可以动态 ...

  4. Developing your first FNC custom control

    Friday, May 13, 2016 Some weeks ago, we released the TMS FNC UI Pack, a set of Framework Neutral Com ...

  5. Android 优化性能之 如何避免--过度绘制

    可能有些人不明白什么是过度绘制,简单言,我们app一个页面所显示的效果是由像素一帧一帧绘制而成.过度绘制就是意味着这一帧被绘制多次.如果是静态的布局,可能影响不是很大,如果是动态的,比如ListVie ...

  6. flume-ng+Kafka+Storm+HDFS 实时系统组合

    http://www.aboutyun.com/thread-6855-1-1.html

  7. Using SetWindowRgn

    Using SetWindowRgn Home Back To Tips Page Introduction There are lots of interesting reasons for cre ...

  8. Struts 上下文

    Struts  上下文 ActionContext .ServletActionContext 是继承关系  ActionContext  ActionContext context = Action ...

  9. 通过jstack定位在线执行java系统故障_案例1

    问题描写叙述: 在一个在线执行的java web系统中,会定时执行一个FTP上传的任务,结果有一天发现,文件正常生成后却没有上传. 问题初步分析: 1.查看日志文件 发现这个任务仅仅打印了開始进入FT ...

  10. Matlab中的取整-floor,ceil,fix,round

    FLOOR Round towards minus infinity. FLOOR(X) rounds the elements of X to the nearest integers toward ...