濮阳杆衣贸易有限公司

主頁 > 知識庫 > asp.net 使用SqlBulkCopy極速插入數(shù)據(jù)到 SQL Server

asp.net 使用SqlBulkCopy極速插入數(shù)據(jù)到 SQL Server

熱門標(biāo)簽:小e電話機(jī)器人 百度地圖標(biāo)注改顏色 申請400電話在哪辦理流程 一個(gè)導(dǎo)航軟件能用幾個(gè)地圖標(biāo)注點(diǎn) 外呼運(yùn)營商線路收費(fèi) 臨沂智能電銷機(jī)器人加盟哪家好 電銷外呼有錄音系統(tǒng)有哪些 鎮(zhèn)江網(wǎng)路外呼系統(tǒng)供應(yīng)商 貴州房產(chǎn)智能外呼系統(tǒng)供應(yīng)商
按這個(gè)來算,我們那個(gè)發(fā)水票的時(shí)間就會由 10分鐘-->20秒,這可太神奇了。
于是乎,下demo,測試,改成自己一般使用的方法測試,NND,還真可以說是極速。
在此貼上我的Demo:SqlBulkCopy.rar
復(fù)制代碼 代碼如下:

using System;
using System.Diagnostics;
using System.Data;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
namespace ConsoleAppInsertTest
{
class Program
{
static int count = 1000000; //插入的條數(shù)
static void Main(string[] args)
{
long sqlBulkCopyInsertRunTime = SqlBulkCopyInsert();
Console.WriteLine(string.Format("使用SqlBulkCopy插入{1}條數(shù)據(jù)所用的時(shí)間是{0}毫秒", sqlBulkCopyInsertRunTime, count));
long commonInsertRunTime = CommonInsert();
Console.WriteLine(string.Format("普通方式插入{1}條數(shù)據(jù)所用的時(shí)間是{0}毫秒", commonInsertRunTime, count));
Console.ReadKey();
}
/// summary>
/// 使用普通插入數(shù)據(jù)
/// /summary>
/// returns>/returns>
private static long CommonInsert()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
for (int i = 0; i count; i++)
{
SqlHelper.ExecuteNonQuery(SqlHelper.SqlConnection, CommandType.Text, "insert into passport(PassportKey) values('" + Guid.NewGuid() + "')");
}
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds;
}
/// summary>
/// 使用SqlBulkCopy方式插入數(shù)據(jù)
/// /summary>
/// returns>/returns>
private static long SqlBulkCopyInsert()
{
Stopwatch stopwatch = new Stopwatch();
stopwatch.Start();
DataTable dataTable = GetTableSchema();
for (int i = 0; i count; i++)
{
DataRow dataRow = dataTable.NewRow();
dataRow[2] = Guid.NewGuid();
dataTable.Rows.Add(dataRow);
}
//Console.WriteLine(stopwatch.ElapsedMilliseconds);//初始化數(shù)據(jù)時(shí)間
SqlBulkCopy sqlBulkCopy = new SqlBulkCopy(SqlHelper.SqlConnection);
sqlBulkCopy.DestinationTableName = "Passport";
if (dataTable != null dataTable.Rows.Count != 0)
{
sqlBulkCopy.WriteToServer(dataTable);
}
sqlBulkCopy.Close();
stopwatch.Stop();
return stopwatch.ElapsedMilliseconds;
}
private static DataTable GetTableSchema()
{
return SqlHelper.ExecuteDataset(SqlHelper.SqlConnection, CommandType.Text, "select * from Passport where 1=2").Tables[0];
}
}
}

轉(zhuǎn)自cnblogs的文章 SQL批量插入數(shù)據(jù)幾種方案的性能詳細(xì)對比
您可能感興趣的文章:
  • 使用SqlBulkCopy時(shí)應(yīng)注意Sqlserver表中使用缺省值的列
  • C#中使用ADOMD.NET查詢多維數(shù)據(jù)集的實(shí)現(xiàn)方法
  • C#數(shù)據(jù)庫操作類AccessHelper實(shí)例
  • C#利用Openxml讀取Excel數(shù)據(jù)實(shí)例
  • C#百萬數(shù)據(jù)查詢出現(xiàn)超時(shí)問題的解決方法
  • C#使用DataSet Datatable更新數(shù)據(jù)庫的三種實(shí)現(xiàn)方法
  • C#應(yīng)用BindingSource實(shí)現(xiàn)數(shù)據(jù)同步的方法
  • C#將Sql數(shù)據(jù)保存到Excel文件中的方法
  • C#中遍歷DataSet數(shù)據(jù)集對象實(shí)例
  • C#使用晚綁定來實(shí)現(xiàn)壓縮Access數(shù)據(jù)庫的方法
  • C# Oracle數(shù)據(jù)庫操作類實(shí)例詳解
  • C#使用SqlBulkCopy批量復(fù)制數(shù)據(jù)到數(shù)據(jù)表

標(biāo)簽:晉城 合肥 嘉興 保定 三明 延邊 澳門 日照

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《asp.net 使用SqlBulkCopy極速插入數(shù)據(jù)到 SQL Server》,本文關(guān)鍵詞  asp.net,使用,SqlBulkCopy,極速,;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《asp.net 使用SqlBulkCopy極速插入數(shù)據(jù)到 SQL Server》相關(guān)的同類信息!
  • 本頁收集關(guān)于asp.net 使用SqlBulkCopy極速插入數(shù)據(jù)到 SQL Server的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    游戏| 沅江市| 华亭县| 故城县| 乌鲁木齐县| 莲花县| 东台市| 峡江县| 安平县| 麻栗坡县| 台东市| 乌拉特中旗| 宝应县| 班戈县| 正安县| 阿拉善左旗| 财经| 丹阳市| 弋阳县| 开化县| 龙陵县| 沧州市| 肇东市| 古田县| 光山县| 孝义市| 神池县| 临沭县| 牙克石市| 扎赉特旗| 石家庄市| 通道| 双峰县| 定远县| 获嘉县| 崇州市| 望城县| 嘉义市| 阳谷县| 女性| 昆山市|