Quantcast
Channel: SQL Server Integration Services forum
Viewing all articles
Browse latest Browse all 24688

Scripting Excel BulkCopy into SQL table and including a id column

$
0
0

Hi All

Using the really good code here, to get excel data in to SQL table:

http://weblogs.asp.net/mikebosch/archive/2007/10/26/ssis-skipping-rows-and-stripping-subtotals.aspx

This works fine .... but I am trying to get a id column in with the insert 

               Dim command As New OleDbCommand("select  * from [" & excelTables(i).ToString() & "A:AL]", excelConnection)

Change the above line to line below. (Note fk_idnumber is not a column from excel)

          

                Dim command As New OleDbCommand("select  1 as fk_idnumber, * from [" & excelTables(i).ToString() & "A:AL]", excelConnection)


                Dim rdr As OleDbDataReader = command.ExecuteReader

                Dim BulkCopy As New SqlBulkCopy(dbconnection)

                BulkCopy.DestinationTableName = "stg_bookon"

                BulkCopy.WriteToServer(rdr)


Interestingly this doesnt break ..... but nothing is inserted. It seems only data from the * (Excel columns) is included 

Any ideas how this can be don?

Thanks

BiF

 


Viewing all articles
Browse latest Browse all 24688

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>