简体   繁体   中英

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. 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. Not sure it'll work, though.

I have used SqlBulkCopy many times and have never encountered a scenario where the leading spaces were removed. 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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