0

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 - Specification and 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...?

deostroll
  • 11,661
  • 21
  • 90
  • 161

2 Answers2

1

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.

zmbq
  • 38,013
  • 14
  • 101
  • 171
0

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...

deostroll
  • 11,661
  • 21
  • 90
  • 161