There is a table with the following columns:
ProdID Specification Value
I've got a csv file with a schema that only has the last two columns -
Value. In other words they are my csv headers. Now I need to associate the values of this file against one unique id.
The significance of that id is that it is a reference to the document; its not important here, but, for now assume it is reqired by the system.
Now while I use the SqlBulkCopy class to insert is there a way that I can still insert some value for ProdID such that each row inserted will have the same ProdID for that file I am trying to bulk copy...?
That depends. if
ProdID is an
identity field in the database, the database will fill it for you when you perform the bulk copy.
If it's not, you will need to fill it yourself and pass the three columns to
SqlBulkCopy, instead of just the two.
You'd have to do something on the lines of the following code:
string cmdTxt = "SELECT " + ProdID + ", * FROM [sample.csv]";
It doesn't matter where you place the ProdID field in the select clause above; in the beginning or end, you'll get the result set with ProdID as the first field...