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

推荐订阅源

Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
Microsoft Azure Blog
Microsoft Azure Blog
Cloudbric
Cloudbric
I
InfoQ
V
V2EX
博客园_首页
The Register - Security
The Register - Security
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
S
Secure Thoughts
Vercel News
Vercel News
Forbes - Security
Forbes - Security
云风的 BLOG
云风的 BLOG
PCI Perspectives
PCI Perspectives
L
LINUX DO - 最新话题
D
DataBreaches.Net
H
Hacker News: Front Page
Application and Cybersecurity Blog
Application and Cybersecurity Blog
B
Blog RSS Feed
A
About on SuperTechFans
N
News and Events Feed by Topic
Apple Machine Learning Research
Apple Machine Learning Research
Help Net Security
Help Net Security
Attack and Defense Labs
Attack and Defense Labs
N
Netflix TechBlog - Medium
Spread Privacy
Spread Privacy
F
Full Disclosure
Recorded Future
Recorded Future
AWS News Blog
AWS News Blog
博客园 - 【当耐特】
The Cloudflare Blog
T
Threatpost
T
Tor Project blog
Google DeepMind News
Google DeepMind News
C
CXSECURITY Database RSS Feed - CXSecurity.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Recent Announcements
Recent Announcements
M
MIT News - Artificial intelligence
A
Arctic Wolf
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
Hacker News - Newest:
Hacker News - Newest: "LLM"
WordPress大学
WordPress大学
Cyberwarzone
Cyberwarzone
小众软件
小众软件
C
Cyber Attacks, Cyber Crime and Cyber Security
P
Proofpoint News Feed
Security Latest
Security Latest
The Last Watchdog
The Last Watchdog

博客园 - 风清云淡

Extjs使用 RestfulWebApi +Token验证小结 Oracle 10g的备份与还原 如何通过反射动态调用泛型方法 Oracle与Sql Server写SQL的区别 Oracle 表与字段的注释操作 将MS SQL SERVER 数据库导入到ORACLE的坑 SQL SERVER 触发器的误区 Asp.net Core部署于CentOS上报404错误的坑 SQL SERVER OVER开窗函数,Partition By,ROW_NUMBER(),DENSE_RANK(),RANK()排名函数 CefSharp"Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies" 在同一个项中引用同一类库的多个版本 Visual Studio中Js使用智能感知 Func<T>,Action<T>,Predicate<T>使用小结 Nuget 在VS中操作命令 Unity的动态加载简单使用 枚举的使用总结 IIS WEB程序如何访问共享目录 AngularJS之页面跳转Route ASP.NET MVC4 BundleConfig的注意事项
SqlBulkCopy 来自数据源的 String 类型的给定值不能转换为指定目标列的类型 bit
风清云淡 · 2017-04-26 · via 博客园 - 风清云淡

使用SqlBulkCopy批量插入,可以快速对大批量的数量插入,性能非常好

在使用时出现“来自数据源的 String 类型的给定值不能转换为指定目标列的类型 bit”异常

为DataTable与要插入的数据表字段位置不一样所至

DataTable与要插入的数据表要字段名,位置,数据类型都一至才可

示例,使用使用SqlBulkCopy插入多个表

        public bool BatchInsertUniqeCode(DataTable uniqueCodeProduceContrastDt,DataTable uniqueCodeGenerateDt)
        {
            using(SqlConnection conn= (SqlConnection)(base.DbContext.Database.Connection))
            {
                if (conn.State == ConnectionState.Closed) { conn.Open(); }
                SqlTransaction tran = conn.BeginTransaction();
                SqlBulkCopy upBlock = new SqlBulkCopy(conn, SqlBulkCopyOptions.Default, tran);
                SqlBulkCopy ugBlock = new SqlBulkCopy(conn, SqlBulkCopyOptions.Default, tran);
                try
                {
                    ugBlock.DestinationTableName = "UniqueCodeGenerate";
                    ugBlock.BatchSize = uniqueCodeGenerateDt.Rows.Count;
                    if (uniqueCodeGenerateDt != null && uniqueCodeGenerateDt.Rows.Count > 0)
                    {
                        ugBlock.WriteToServer(uniqueCodeGenerateDt);
                    }
                    ugBlock.Close();


                    upBlock.DestinationTableName = "UniqueCodeProduceContrast";
                    upBlock.BatchSize = uniqueCodeProduceContrastDt.Rows.Count;
                    if (uniqueCodeProduceContrastDt != null && uniqueCodeProduceContrastDt.Rows.Count > 0)
                    {
                        upBlock.WriteToServer(uniqueCodeProduceContrastDt);
                    }
                    upBlock.Close();

                    tran.Commit();
                    return true;
                }
                catch(Exception ex)
                {
                    tran.Rollback();
                    throw ex;
                }
                finally
                {
                    upBlock.Close();
                    ugBlock.Close();
                    conn.Close();
                }

            }

        }