Scripting Excel BulkCopy into SQL table and including a id column
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
September 19th, 2012 11:27am

why you are doing this through code? you can create a ssis package, add a data flow task use an excel source pointing to your excel file use a Derived Column transformation to create other columns based on some expressions (for example static expression 1 can be a column) and then load whole data stream into destinations like OLE DB or any other destinationhttp://www.rad.pasfu.com
Free Windows Admin Tool Kit Click here and download it now
September 19th, 2012 5:09pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics