• 大小: 323.57 KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2024-11-29
  • 语言: 数据库
  • 标签: Net  C#  

资源简介

4秒100万条数据导入SQL数据库-NET(C#)demo

试验的5种方法,比较各种方法的导入速度

基本Insert Into
单线程Bulk Insert
多线程Bulk Insert
单线程SqlBulkCopy
多线程SqlBulkCopy

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using IsLine.Data.DataProvider;

namespace ToSqlServer
{
    public partial class InsertInto : Form
    {
        public static StringBuilder sb = null;
        public static string sql = ““;

        public InsertInto()
        {
            InitializeComponent();
            sql = GetSql();
        }

        private void InsertInto_Load(object sender EventArgs e)
        {

        }

        private void button1_Click(object sender EventArgs e)
        {
            
            System.Diagnostics.Stopwatch timer = new System.Diagnostics.Stopwatch();
            timer.Start();

            for (int i = 0; i < 5; i++)
                SqlProvider.ExecuteNonQuery(sql true CommandType.Text null); //调用了IsLine frameWork中的方法,第二个参数表示开启了事务

            timer.Stop();        
            MessageBox.Show(timer.ElapsedMilliseconds.ToString());

        }
        private string GetSql()
        {
            sb = new StringBuilder();
            try
            {
                for (int i = 0; i < 199999; i++)
                {
                    sb.Append(“insert into TableB (value1) values (‘“ + i + “‘)!“);
                }
                sb.Append(“insert into TableB (value1) values (‘200000‘)“);
                return sb.ToString();
            }
            finally
            {
                sb = null;
                GC.Collect();
            }
        }
    }
}

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件        920  2010-03-16 15:08  sqltest.sln

    ..A..H.     33280  2010-03-16 15:08  sqltest.suo

     目录          0  2010-03-16 15:06  sqltest1

     文件        240  2010-03-16 15:06  sqltest1\App.config

     目录          0  2010-03-14 12:56  sqltest1\bin

     目录          0  2010-03-16 13:42  sqltest1\bin\Debug

     文件        251  2010-03-05 09:17  sqltest1\bin\Debug\App.config

     目录          0  2010-03-16 13:42  sqltest1\bin\Debug\app.publish

     目录          0  2010-03-16 13:42  sqltest1\bin\Debug\app.publish\Application Files

     目录          0  2010-03-16 13:42  sqltest1\bin\Debug\app.publish\Application Files\ToSqlServer_1_0_0_5

     文件      31232  2010-03-16 11:44  sqltest1\bin\Debug\app.publish\Application Files\ToSqlServer_1_0_0_5\IsLine.DataProvider.dll.deploy

     文件       4608  2009-06-12 13:36  sqltest1\bin\Debug\app.publish\Application Files\ToSqlServer_1_0_0_5\IsLine.dll.deploy

     文件      12288  2009-06-12 13:36  sqltest1\bin\Debug\app.publish\Application Files\ToSqlServer_1_0_0_5\IsLine.HttpContentProvider.dll.deploy

     文件       7168  2009-05-06 11:36  sqltest1\bin\Debug\app.publish\Application Files\ToSqlServer_1_0_0_5\IsLine.SecurityProvider.dll.deploy

     文件        251  2010-03-16 13:42  sqltest1\bin\Debug\app.publish\Application Files\ToSqlServer_1_0_0_5\ToSqlServer.exe.config.deploy

     文件      17920  2010-03-16 13:42  sqltest1\bin\Debug\app.publish\Application Files\ToSqlServer_1_0_0_5\ToSqlServer.exe.deploy

     文件      10152  2010-03-16 13:42  sqltest1\bin\Debug\app.publish\Application Files\ToSqlServer_1_0_0_5\ToSqlServer.exe.manifest

     文件     461768  2010-03-16 13:42  sqltest1\bin\Debug\app.publish\setup.exe

     文件       5325  2010-03-16 13:42  sqltest1\bin\Debug\app.publish\ToSqlServer.application

     文件      31232  2010-03-16 11:44  sqltest1\bin\Debug\IsLine.DataProvider.dll

     文件       4608  2009-06-12 13:36  sqltest1\bin\Debug\IsLine.dll

     文件      12288  2009-06-12 13:36  sqltest1\bin\Debug\IsLine.HttpContentProvider.dll

     文件       7168  2009-05-06 11:36  sqltest1\bin\Debug\IsLine.SecurityProvider.dll

     文件        251  2010-03-05 09:17  sqltest1\bin\Debug\sqltest1.vshost.exe.config

     文件       1579  2010-03-16 15:08  sqltest1\bin\Debug\ToSqlServer.application

     文件      17920  2010-03-16 15:08  sqltest1\bin\Debug\ToSqlServer.exe

     文件        240  2010-03-16 15:06  sqltest1\bin\Debug\ToSqlServer.exe.config

     文件       6481  2010-03-16 15:08  sqltest1\bin\Debug\ToSqlServer.exe.manifest

     文件      65024  2010-03-16 15:08  sqltest1\bin\Debug\ToSqlServer.pdb

     文件       1579  2010-03-16 15:08  sqltest1\bin\Debug\ToSqlServer.vshost.application

............此处省略64个文件信息

评论

共有 条评论