I am receiving this error when trying to do a bulk copy to my SQL Server db in my ASP.NET MVC project
The given value of type String from the data source cannot be converted to type nvarchar of the specified target column.
I have looked through similar issues and found 1 which helped me pinpoint my issue: c# can't insert data table using sqlbulkcopy. I would like to point out the answer given by KatieAmber:
I have another answer for this question, maybe it can come in handy for someone. If you have a String which contains " (quotation mark), you get this error message too. At least I just got this error message, and I searched for the wrong row, and I found this. As I removed the quotation marks, the error disappeared.
So when looking at the data in my .csv
I noticed that the GPS coordinates were all enclosed in quotes, like this "-29.721447,31.066920". Of course in this case, I immediately realised that I cannot remove the quotes as this single lat, long value would then become 2 separate values, separated by the comma.
So my question is, is there a possible way to work around this? Could I possibly patch my SqlBulkCopy
to accept the quoted string? Or maybe specify another separator?