0

I was wondering if there was a way to qualify the table mappings when using sqlbulkcopy in c#?

Currently, I have a table that contains Stock Codes and then columns associated with range of weekly bucks.

example:

Stock Code | 11-2013 | 12-2013| 13-2013 | 14-2013 etc etc.

I have a query that returns quantities for the given stock code and the week number in which they occurred.

example:

part a | 20 | 11-2013

part b | 10 | 14-2013

Ideally, there would be a way to set the columnmappings.add method and specify that I would like to map the date column of the table to the resulting date in the return row of the query. I would show what I have; however, I have no idea if this is even possible. Any suggestions or alternative ideas would be great.

Thanks

DoNotArrestMe
  • 1,285
  • 1
  • 9
  • 20
user2859487
  • 23
  • 1
  • 2
  • 5
  • You can specific column mappings by name. Not sure what I am missing here. – Cam Bruce Jan 17 '14 at 22:10
  • You would have to do this yourself. I.E, read the source data rows and create target datarows filling up the columns and then submit to SQLBulkCopy as they were ready. – RBarryYoung Jan 17 '14 at 22:13
  • 1
    What you *CAN* do is to change your source query to pivot the rows into columns for you. Assuming that your source is SQL Server or some other SQL DBMS. – RBarryYoung Jan 17 '14 at 22:14

1 Answers1

1

Not directly possible. Your source data has to match to your destination data. The SqlBulkCopy class isn't going to do that for you.

Create a sql query from your source data that matches the table schema of your destination table. Then you can use the SqlBulkCopy class.

Cam Bruce
  • 5,632
  • 19
  • 34