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

推荐订阅源

cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
C
CERT Recently Published Vulnerability Notes
C
Cybersecurity and Infrastructure Security Agency CISA
P
Proofpoint News Feed
Security Latest
Security Latest
P
Privacy International News Feed
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
AI
AI
Cisco Talos Blog
Cisco Talos Blog
K
Kaspersky official blog
S
Secure Thoughts
PCI Perspectives
PCI Perspectives
Simon Willison's Weblog
Simon Willison's Weblog
D
DataBreaches.Net
GbyAI
GbyAI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
大猫的无限游戏
大猫的无限游戏
T
Tailwind CSS Blog
The Cloudflare Blog
阮一峰的网络日志
阮一峰的网络日志
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
罗磊的独立博客
V
Visual Studio Blog
aimingoo的专栏
aimingoo的专栏
H
Hackread – Cybersecurity News, Data Breaches, AI and More
IT之家
IT之家
V
V2EX
Last Week in AI
Last Week in AI
有赞技术团队
有赞技术团队
月光博客
月光博客
酷 壳 – CoolShell
酷 壳 – CoolShell
T
Tenable Blog
T
Threat Research - Cisco Blogs
T
Troy Hunt's Blog
V2EX - 技术
V2EX - 技术
S
Security @ Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Project Zero
Project Zero
The GitHub Blog
The GitHub Blog
Recent Commits to openclaw:main
Recent Commits to openclaw:main
L
Lohrmann on Cybersecurity
F
Full Disclosure
H
Help Net Security
博客园 - Franky
Stack Overflow Blog
Stack Overflow Blog
N
Netflix TechBlog - Medium
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
O
OpenAI News
S
Securelist

博客园 - 溶入海洋中的雨滴

ADO Entities Framework不对多表查询进行优化? case when遇上null值 【转】C#正则表达式整理备忘 【摘】UI设计中对比色颜色的选取 JavaScript中的正则表达式解析 JavaScript正则表达式exec和test方法实例! - 溶入海洋中的雨滴 - 博客园 用js实现用回车键、ctrl键在文本框导航 [原]无刷新三级连动用户控件 SQL:定时作业的设置方法 【转】c#用柱形图、折线图和饼形图展示数据 【原】css设置布局时,尽量天上背景色 【原】JS控制控件的显示,你选择display还是visibilty 【原】js实现2个listbox的乾坤大挪移 [转]数据库设计14个技巧 【转】sql查询性能调试,用SET STATISTICS IO和SET STATISTICS TIME 【原】winform定制datagrid模板 【原】winform高效导出Excel带格式设置 【原】让3层下的objectDatasource,支持griedview不写代码具备编辑功能 推荐一个可以下.net电子书的论坛
c#批量插入数据到数据库【支持事务操作】
溶入海洋中的雨滴 · 2008-06-26 · via 博客园 - 溶入海洋中的雨滴

  #region  批量插入数据到数据库
            DateTime startTime; 
            private bool SqlBulkCopy(DataTable dt)
            {

                try
                {
                    startTime = DateTime.Now;
                    //数据批量导入sqlserver,创建实例    SqlBulkCopyOptions.UseInternalTransaction采用事务  复制失败自动回滚
                    System.Data.SqlClient.SqlBulkCopy sqlbulk = new System.Data.SqlClient.SqlBulkCopy(System.Configuration.ConfigurationSettings.AppSettings["ConStr"], SqlBulkCopyOptions.UseInternalTransaction);
                    sqlbulk.SqlRowsCopied +=
                    new SqlRowsCopiedEventHandler(OnRowsCopied); //订阅复制完成后的方法,参数是 sqlbulk.NotifyAfter的值
                    sqlbulk.NotifyAfter = dt.Rows.Count;

                    //目标数据库表名
                    sqlbulk.DestinationTableName = "T_TempUpLoadTC";
                    //数据集字段索引与数据库字段索引映射
                    sqlbulk.ColumnMappings.Add(0, "userName");
                    sqlbulk.ColumnMappings.Add(1, "JiFenCount");
                    //导入
                    sqlbulk.WriteToServer(dt);
                    sqlbulk.Close();
                    return true;
                }
                catch (Exception ex)
                {
                    throw new Exception(ex.Message);
                }
                finally 
                {
                    dt.Dispose();
                }
            }

            //复制完成后的处理事件
            private void OnRowsCopied(object sender, SqlRowsCopiedEventArgs args)
            {
                lblCounter.Text += args.RowsCopied.ToString() + " 条记录已导入";
                TimeSpan copyTime = DateTime.Now - startTime;
                lblCounter.Text += "  花费时间:" + copyTime.Seconds.ToString() + "." +
                copyTime.Milliseconds.ToString() + " 秒";
            }
          #endregion