Add text when using SQLBulkCopy in SQL Server from excel

I created a page where our partners can upload excel files with statistics using SQLBulkCopy. The file has multiple sheets and I need to add the sheet name to a column in the DB for each row. Sheet names will not change so hard that the names are approved. How can I solve this?

0


source to share


1 answer


Since the sheet name does not change, I solved it this way:



  • Created a temporary table with the same layout as final.

  • Imported data from the first sheet into a temporary table.

  • Populated a column that was now null with the correct value.

  • Made nr 2-> 3 for next sheet until all sheets are imported.

  • Checks the temporary table for errors.

  • I imported the data from the temporary table into the summary table one row at a time to be able to determine if records exist and if it is an update and also insert them.

0


source







All Articles