简体   繁体   English

SQL SqlBulkCopy是否不删除列中的前导空格?

[英]Have SQL SqlBulkCopy NOT remove leading spaces in column?

So Im using SqlBulkCopy to insert records into my database, but when doing so it is removing any leading spaces in my column. 因此,我使用SqlBulkCopy将记录插入到数据库中,但是这样做是在删除列中的前导空格。 Is there a way for it not to do so? 有没有办法不这样做? Please help! 请帮忙!

You could try plaing double quotes around the values. 您可以尝试在值周围使用简单的双引号。 That's what you do when you use bcp, SqlBulkCopy's great uncle. 这就是使用SqlBulkCopy的叔叔bcp时要做的事情。 Not sure it'll work, though. 不过,不确定它是否会工作。

I have used SqlBulkCopy many times and have never encountered a scenario where the leading spaces were removed. 我已经多次使用SqlBulkCopy,但从未遇到删除前导空格的情况。 In fact to achieve this I have had to explicitly find records with leading spaces and remove them. 实际上,要实现这一点,我必须明确地找到带有前导空格的记录并将其删除。 Can you provide more information like the scenario in which you are encountering this please? 您能否提供更多信息,例如遇到这种情况的场景?

If your source is a text file and you are probably using an OleDb text driver, then the OleDb trims the spaces, therefore you might want to check if the spaces are being trimmed before its sent to SqlBulkCopy. 如果源是文本文件,并且您可能正在使用OleDb文本驱动程序,则OleDb会修剪空格,因此,在将空格发送到SqlBulkCopy之前,您可能需要检查是否已修剪空格。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM