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();

 

 

相关文章:

  • 2021-04-11
  • 2022-02-15
  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2021-10-21
  • 2021-05-03
  • 2021-12-31
猜你喜欢
  • 2022-12-23
  • 2021-04-07
  • 2022-12-23
  • 2021-09-03
  • 2022-01-30
  • 2022-12-23
  • 2021-12-30
相关资源
相似解决方案