Uploading a csv file to sql server - Identity problem.

Posted by Doozer1979 on Stack Overflow See other posts from Stack Overflow or by Doozer1979
Published on 2011-01-10T13:51:34Z Indexed on 2011/01/10 13:53 UTC
Read the original article Hit count: 258

Filed under:
|
|
|
|

Given a column structure in a CSV file of:

First_Name, Last_Name, Date_Of_Birth

And a SQL Server table with a structure of

ID(PK) | First_Name | Last_Name | Date_Of_Birth

(Field ID is an Identity with an auto-increment of 1)

How do i arrange it so that SQL Server does not attempt to insert the First_Name column from the csv file into the ID field?

For info the csv is loaded into a DataTable and then copied to SQL Server using SqlBulkCopy

Should i be modifying the csv file before the import add the ID column (The destination table is truncated prior to import, so no need to worry about duplicate key values.) Or perhaps adding an id column to the Datatable?

Or Is there a setting in Sql Server that i may have missed?

© Stack Overflow or respective owner

Related posts about c#

Related posts about .NET