使用默认参数进行批量复制 [英] Bulk Copy with default parameters

查看:53
本文介绍了使用默认参数进行批量复制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用BulkCopy类将DataTable插入数据库表中.
已知源和目标是相同的表(不同的位置...),但是有些值不应该传递,并且在批量插入过程中实际上不存在.我什么意思看下面的例子

可以说表具有相同的结构:Column1-Column 10

但是,当移动数据时,将跳过Column5(让我们说私有),因此每一行中此列的值应为默认值.

因此,数据表的标头是这样的:
Column1,Column2,...,Column4,Column6,... Column10

目前,跳过第5列"为我提供了例外(由于我认为是不同的数据类型...),我该怎么办?



没关系,我使用了列映射...

解决方案

而不是直接的INSERT语句,您需要使用列映射的INSERT作为

  INSERT  (col1,col2,col3,col4,col6) VALUES ( 1  2  3  4  6 )

/blockquote>

I''m using the BulkCopy class to insert a DataTable into a database table.
The origin and the target are known to be identical tables (different locations...), but there are some values that shouldn''t be passed, and actually are not there during the bulk insertion. What do I mean? Look at the following example

Lets say that the tables have the same structure: Column1 - Column 10

But when moving the data, Column5 is skipped (lets say private), and therefore the value for this column within each and every row should be the default value.

So the datatable''s header is something like this:
Column1, Column2, ..., Column4, Column6, ... Column10

Currently, Skipping Column 5 is giving me exceptions (because of different datatypes I think...) What should I do?

EDIT:

Nevermind, I used Column Mappings...

解决方案

Instead of straight INSERT statement, you need to use column mapped INSERT as

INSERT table (col1, col2, col3, col4, col6) VALUES (1, 2, 3, 4, 6)


这篇关于使用默认参数进行批量复制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆