1、sql2008中 list表,只有一个字段 Lvalue
2、文本大约256万的数据量
3、测试结果:用时36秒!
string connStr = @"Data Source=.\SQLEXPRESS;Initial Catalog=test1;Persist
Security Info=True;User ID=sa;Password=123456";
DataTable dt =
new DataTable();
dt.Columns.Add("Lvalue");
Stopwatch sw = new Stopwatch();
sw.Start();
IEnumerable lines = File.ReadLines(@"F:\1.txt", Encoding.Default);
DataRow row ;
foreach (string str in lines)
{
try
{
row =
dt.NewRow();
row["Lvalue"] = str;
dt.Rows.Add(row);
}
catch (Exception
ex)
{
//数据量超大时,会内存溢出
throw;
}
}
using (SqlBulkCopy bulkCopy = new
SqlBulkCopy(connStr))
{
bulkCopy.DestinationTableName = "list";
bulkCopy.ColumnMappings.Add("Lvalue", "Lvalue");
bulkCopy.WriteToServer(dt);
}
long ssww=
sw.ElapsedMilliseconds;
sw.Stop();
c# 将文本中的数据快速导入到数据库(200万左右的数据量),布布扣,bubuko.com
c# 将文本中的数据快速导入到数据库(200万左右的数据量)
原文:http://www.cnblogs.com/lanleiming/p/3584582.html