惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

AI
AI
TaoSecurity Blog
TaoSecurity Blog
H
Heimdal Security Blog
Help Net Security
Help Net Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
Microsoft Azure Blog
Microsoft Azure Blog
www.infosecurity-magazine.com
www.infosecurity-magazine.com
Google DeepMind News
Google DeepMind News
爱范儿
爱范儿
The Cloudflare Blog
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
人人都是产品经理
人人都是产品经理
大猫的无限游戏
大猫的无限游戏
N
News | PayPal Newsroom
V2EX - 技术
V2EX - 技术
博客园 - 【当耐特】
D
Darknet – Hacking Tools, Hacker News & Cyber Security
S
Secure Thoughts
C
CERT Recently Published Vulnerability Notes
罗磊的独立博客
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
P
Privacy & Cybersecurity Law Blog
有赞技术团队
有赞技术团队
S
Schneier on Security
S
SegmentFault 最新的问题
Google Online Security Blog
Google Online Security Blog
H
Hacker News: Front Page
The Last Watchdog
The Last Watchdog
Schneier on Security
Schneier on Security
PCI Perspectives
PCI Perspectives
IT之家
IT之家
Project Zero
Project Zero
博客园 - 司徒正美
P
Privacy International News Feed
Recent Commits to openclaw:main
Recent Commits to openclaw:main
Jina AI
Jina AI
Security Latest
Security Latest
Hacker News - Newest:
Hacker News - Newest: "LLM"
腾讯CDC
C
CXSECURITY Database RSS Feed - CXSecurity.com
阮一峰的网络日志
阮一峰的网络日志
C
Check Point Blog
aimingoo的专栏
aimingoo的专栏
V
Vulnerabilities – Threatpost
W
WeLiveSecurity
NISL@THU
NISL@THU
Webroot Blog
Webroot Blog
N
Netflix TechBlog - Medium
L
Lohrmann on Cybersecurity

博客园 - 菜鸟吴迪

Lucene搜索结果排序问题(按时间倒序排的替代解决方法) 利用Lucene.net搜索引擎进行多条件搜索的做法 (转) (转)Razor引擎学习:RenderBody,RenderPage和RenderSection ASP.NET MVC3 返回多个实体或泛型 MySQL数据库集群Master-Slave模式安装摘要 使用HtmlAgilityPack批量抓取网页数据 Jquery each - 菜鸟吴迪 - 博客园 堆?栈?(转) 数据库并发控制!!! Velocity脚本简明教程 Visual Studio的调试技巧 《C#与.NET3.5高级程序设计(第4版)》笔记10 sql分页问题,老话题!! sql查询连续三天之内都有记录的人员!! Asp.net Mvc Controller接收可控的数组或字典类型的实现方法: SELECT INTO 和 INSERT INTO SELECT 两种表复制语句 (转) httpContext里面的东西!!! c#闭包!! c#新特性!!!
读取txt文本,批量插入到数据库中!
菜鸟吴迪 · 2012-08-02 · via 博客园 - 菜鸟吴迪

约700万条数据,耗时约5分钟,

 

protected void Page_Load(object sender, EventArgs e)
        {
            string path="D://1.TXT";
            string[] arr={"code","UserId","IsEncash","EncashDateTime","CreateTime","Mark"};
            DataSet ds = TextFileLoader(path, "tb", arr);

            int count = ds.Tables[0].Rows.Count;
            BulkInsert(ds.Tables[0]);
                   
            }

  /**/
        /**/
        /**/
        /// <summary>
        
/// 文件加载
        
/// </summary>
        
/// <param name="FilePath">带文件名的路径</param>
        
/// <param name="TableName">自定义的表名</param>
        
/// <param name="FieldsInArray">自定义的表字段</param>
        
/// <returns>DataSet</returns>

        public static DataSet TextFileLoader(string FilePath, string TableName, string[] FieldsInArray)
        {
            DataSet ds = new DataSet();
            DataTable dt = new DataTable(TableName);

            FileStream fs = File.Open(FilePath, FileMode.Open, FileAccess.Read);
            StreamReader sr = new StreamReader(fs);

            for (int i = 0; i < FieldsInArray.Length; i++)
            {
                dt.Columns.Add(new DataColumn(FieldsInArray[i], typeof(string)));
            }

            string strRead;
            bool flag = true;

            while (flag)
            {
                strRead = sr.ReadLine();

                if (!string.IsNullOrEmpty(strRead))
                {
                    string[] aryVale = strRead.Split('\t');

                    DataRow dr = dt.NewRow();
                    for (int k = 0; k < aryVale.Length; k++)
                    {
                        dr[FieldsInArray[k]] = aryVale[k];
                    }
                    dt.Rows.Add(dr);
                }
                else
                {
                    flag = false;
                }
            }

            ds.Tables.Add(dt);
            return ds;

        }

        private void BulkInsert(DataTable  dt) {
            string time = String.Empty;

            DateTime beginTime = DateTime.Now;

            using (SqlBulkCopy bulk = new SqlBulkCopy(System.Configuration.ConfigurationManager.ConnectionStrings["connectionString"].ToString())) 
            {

                //{"code","UserId","IsEncash","EncashDateTime","CreateTime","Mark"}
                bulk.BatchSize = 1000;
                bulk.DestinationTableName = "OfficeEncashOne";
                bulk.ColumnMappings.Add("code""code");
                bulk.ColumnMappings.Add("UserId""UserId");
                bulk.ColumnMappings.Add("IsEncash""IsEncash");
                bulk.ColumnMappings.Add("EncashDateTime""EncashDateTime");
                bulk.ColumnMappings.Add("CreateTime""CreateTime");
                bulk.ColumnMappings.Add("Mark""Mark"); 
                
                
                bulk.WriteToServer(dt); 
            } 
            DateTime endTime = DateTime.Now; 
            TimeSpan useTime = endTime - beginTime; 
            dt.Dispose(); 
            time = "使用时间" + useTime.TotalSeconds.ToString() + ""
        }