4

I am reading CSV files and dynamically creating database tables based on headers of CSV files.

But getting problem while reading csv data and dumping in to relevant tables. The problem comes when I have a column with decimal datatype and CSV fields contains blank so it is treated as string and getting below error.

Error :

Failed to convert parameter value from a String to a Decimal.

I am using CSV Helper and through class map, maybe I can achieve this but I am dynamically creating structure based on CSV files so I can't define any fixed class.

Here is 1 answer I found which might be helpful in case of class map: Using CsvHelper can I translate white space to a nullable?

Sample Record :REcord

Problem occurs when sqlbulk copy tries to dump those data in SQL Server database table.

1 Answer 1

1

I think that you might need to do column mapping. If you are using SqlBulkCopy you can use some of what is described on this post:

Mapping columns in a DataTable to a SQL table with SqlBulkCopy

Sign up to request clarification or add additional context in comments.

1 Comment

I have already done column mappings and when i insert data in those blank records then i dont get any error

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.