1、问题:导入大数据量到数据库,用我们普通的SqlHelper来做是每插入一条都是打开连接关闭连接,这样太慢,因此我们会想到让SqlConnection一直打开直到所有数据都插入完成再关闭连接。但是根据数据库连接池,这样速度依然很慢。

2、解决办法: .Net给我们提供了SqlBulkCopy来一次性执行插入,效率和速度要高很多

3、实例:

如:导入手机号码归属地信息

准备材料:"手机号段归属地数据库.txt"文档。

如在Winform中添加按钮,按钮的点击事件中实现。

#code

private void btn_import_Click(object sender, RoutedEventArgs e)
{
//先读取文件
//打开对话框,选择文件。
OpenFileDialog ofd = new OpenFileDialog();
ofd.Filter = "文本文件|*.txt";
if (ofd.ShowDialog()==false)
{
return;
}
string[] lines = File.ReadLines(ofd.FileName,Encoding.Default).ToArray(); DateTime startTime = DateTime.Now; //新建表
DataTable dtTable = new DataTable();
//给表添加列
dtTable.Columns.Add("StartTellName");
dtTable.Columns.Add("TellType");
dtTable.Columns.Add("TellArea"); //遍历每一行数据,处理数据,添加到行(DataRow)中
foreach (string line in lines)
{
string[] strs = line.Split('\t');//\t制表符
string startTellNum = strs[];
string tellType = strs[].Trim('"');//去除两边的"
string tellArea = strs[].Trim('"');
DataRow row = dtTable.NewRow();
row["StartTellName"] = startTellNum;//给字段赋值
row["TellType"] = tellType;
row["TellArea"] = tellArea;
dtTable.Rows.Add(row);//添加到一行中
} //获取配置文件中连接字符串
string connstr = ConfigurationManager.ConnectionStrings["connstr"].ConnectionString; //SqlBulkCopy是实现IDisposable接口的,所以必须用using
using (SqlBulkCopy bulk = new SqlBulkCopy(connstr))
{
bulk.DestinationTableName = "T_TellNum";//指定表名
//本地列名与数据库列名建立连接
bulk.ColumnMappings.Add("StartTellName", "starttellnum");
bulk.ColumnMappings.Add("TellType", "telltype");
bulk.ColumnMappings.Add("TellArea", "tellarea");
//把dtTable的数据写到数据库
bulk.WriteToServer(dtTable);
}
TimeSpan ts = DateTime.Now - startTime;
//计算时间
MessageBox.Show(ts.ToString());
}

#code

4、数据库字段

  id bigint primary key,

starttellnum nvarchar(30),

telltype  nvarchar(30),

tellarea  nvarchar(30),

5、可能遇到的问题

aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAcMAAADuCAIAAADKofvVAAAgAElEQVR4nO2dbUwbaYLn8d7t9N59WJ3uPp2wRjva3d4Y7Z400s704dmxpYumL7Qu0vTQsx9u7pQoxLZ0JyWdSNfQI6WFNzBSd5MmLXVCwNCd6cCKmcmkAwZ3km7STdLpkFCE6WCTBNsQAzGE9xeDAdvl+/DUy1NVT9ll3kLC/6+/nKJSrnrKrvrV/3mpcl6PfwiGYRhetys//DTvmRcChmH4uTZICsMwvFHnRlKub/D617efeaFhGIZ3lHMj6e/+8NmNGxevffXtMy83DMPwznEOJL1xu/fSpYujwZfar3Svd3tdJ1+3m1+v8TH+67KzwP7q+106fw41HLWbC4gPOo8eFKdlOxu3+MPqqHm1QCw8mT56WbtYw1G7ueDgyY5n/dXql3Dn+nksMwz7h3pyImlLS0eY+4t02vTFv9r/+JlvXdvTJ2njO0oAqUna4x/yvX/QXPBOgzzRdfJ1u/noZXIGakkqw3dTTs71kZQsKV4DtpSwvvcPypvYEJUuO7frKrV5ZYbhZ2mjJG27cr3zq5pzZ/7xrf+3N3TvL7/t6uu+Hza2DfVpqfQ7Df6hHuGMomfubJLqmyapcqe2nEqbF4e3j6Q7JcLDsMbk4M88R7IhknJ9g4H+4cd9L5W+9b+czv/77ec/+PrC33vbO3IvnF4m7Tr5usBNkZKEpDVO6jRTktQIoQgR3mnwyxxsEN/rbBTLo8pEr9f4hPnKIJkhk0rB8+hlGQ3iTKlgYrHZ5VG1bChmigufPGqXLyGK4tFz5KsLdQmh4ShcvXQ+E+XnJlq4LJEVNr5jli8q1KaFzemWX7mzm1tmGN580+jMgNEegyT946XWm5+70kv/6djRV1/97//jTtt/Xn3w7wbuX7955z7XN5hLyXRISp1CDUfJAtRZJC6fayZlkJT26zU+kW7CCd/4jjitDGU0PRkk1Ybugyc7RNwo4jAFbm15BCay8qBiYeEyoyxeZippS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zugAAAABJRU5ErkJggg==" alt="" />

解决办法:请检查建立连接字段时字段名是否都正确。

解决方法

1,首先检查数据库表的字段是否过小

2,检查数据中是否有类似单引号的数据,做一下过滤

SqlBulkCopy的使用的更多相关文章

  1. 【Update】C# 批量插入数据 SqlBulkCopy

    SqlBulkCopy的原理就是通过在客户端把数据都缓存在table中,然后利用SqlBulkCopy一次性把table中的数据插入到数据库中. SqlConnection sqlConn = new ...

  2. [小干货]SqlBulkCopy简单封装,让批量插入更方便

    关于 SqlServer 批量插入的方式,前段时间也有大神给出了好几种批量插入的方式及对比测试(http://www.cnblogs.com/jiekzou/p/6145550.html),估计大家也 ...

  3. C# 数据批量插入到数据库SqlBulkCopy(源数据类型:List<T> Or DataTable)

      /*_____________________ List<T>类型数据 To Sql_______________________________*/ /// <summary& ...

  4. 用SqlBulkCopy批量安插数据时提示来自数据源的 String 类型的给定值不能转换为指定目标列的类型 int

    dr["description"] = ds.Tables[0].Rows[i]["组织描述"].ToString();                dr[& ...

  5. .Net批量插入数据到SQLServer数据库,System.Data.SqlClient.SqlBulkCopy类批量插入大数据到数据库

    批量的的数据导入数据库中,尽量少的访问数据库,高性能的对数据库进行存储. 采用SqlBulkCopy来处理存储数据.SqlBulkCopy存储大批量的数据非常的高效,将内存中的数据表直接的一次性的存储 ...

  6. 【转】批量复制操作(SqlBulkCopy)的出错处理:事务提交、回滚

    原文地址:http://blog.csdn.net/westsource/article/details/6658109 默认情况下,批量复制操作作为独立的操作执行. 批量复制操作以非事务性方式发生, ...

  7. 【记录】SqlBulkCopy 跨数据库,表自定义导入

    使用场景: 一个数据库中的表数据,导入到另一个数据库中的表中,这两个表的表结构不一样,如果表结构一样的时候,导入非常简单,直接读取导入就行了,表结构不一样,就意味着需要加入一些判断,SqlBulkCo ...

  8. sql 中的Bulk和C# 中的SqlBulkCopy批量插入数据 ( 回顾 and 粗谈 )

    通常,我们会对于一个文本文件数据导入到数据库中,不多说,上代码. 首先,表结构如下.   其次,在我当前D盘中有个文本文件名为2.txt的文件. 在数据库中,可以这样通过一句代码插入. Bulk in ...

  9. IBatis 批量插入数据之SqlBulkCopy

    public void AddLetters(IList<int> customerIds, string title, string content, LetterEnum.Letter ...

  10. C# 使用SqlBulkCopy类批量复制大数据

    用途说明: 前些日子,公司要求做一个数据导入程序,要求将Excel数据,大批量的导入到数据库中,尽量少的访问数据库,高性能的对数据库进行存储.于是在网上进行查找,发现了一个比较好的解决方案,就是采用S ...

随机推荐

  1. APM代码学习笔记2:编译过程

    make编译 所有位置的Makefile 引用的都是/mk/apm.mk target.mk 设置CONFIG_HAL_BOARD 例如linux就是HAL_BOARD_LINUX environ.m ...

  2. 再探Delphi2010 Class的构造和析构顺序

    发了上一篇博客.盒子上有朋友认为Class的构造和析构延迟加载.是在Unit的初始化后调用的Class的构造.在Unit的反初始化前调用的Class的析构函数. 为了证明一下我又做了个试验 unit ...

  3. 转:C++中多态是怎样实现的?

    多态是一种不同的对象以单独的方式作用于相同消息的能力,这个概念是从自然语言中引进的.例如,动词“关闭”应用到不同的事务上其意思是不同的.关门,关闭银行账号或关闭一个程序的窗口都是不同的行为:其实际的意 ...

  4. //Build/ 2014 开发者大会Azure重点整理

     寓教于乐,轻松掌握 Windows Apps和 Cloud //Build/ 2014开发者大会第二天重点整理 (上) //Build/ 2014开发者大会第二天的主题演讲主要包含两部分:Mic ...

  5. nyoj三个水杯(bfs)

    三个水杯 时间限制:1000 ms  |           内存限制:65535 KB 难度:4   描述 给出三个水杯,大小不一,并且只有最大的水杯的水是装满的,其余两个为空杯子.三个水杯之间相互 ...

  6. The Highest Mark(01背包)

    The Highest Mark Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Other ...

  7. uva 11137 Ingenuous Cubrency(完全背包)

    题目连接:11137 - Ingenuous Cubrency 题目大意:由21种规模的立方体(r 1~21),现在给出一个体积, 要求计算可以用多少种方式组成. 解题思路:完全背包, 和uva674 ...

  8. c++类的实例化,有没有new的区别

    A a; A * a = new a(); 以上两种方式皆可实现类的实例化,有new的区别在于: 1.前者在堆栈中分配内存,后者为动态内存分配,在一般应用中是没有什么区别的,但动态内存分配会使对象的可 ...

  9. iOS网络开发-打造自己的视频客户端

    一.展示实现 效果      客户端:                                      服务器端:            二.创建表 create table CourseV ...

  10. 前缀 树 背单词(Remember the Word,LA 3942)

    已哭瞎. 搞了2个多小时的错误居然是在  没有初始化............教训:每个例子一定要考虑到初始化问题.! 每个节点存了一个数组  该数组记录的有26个大小  0-25分别表示记录表示'a' ...