Avatar of mascoloj
mascoloj
Flag for United States of America asked on

SqlBulkCopyColumnMapping

I am performing a SQLBulkCopy which is working fine except I would like to get some info on SqlBulkCopyColumnMapping. I have 2 columns that are being mapped out of 20, the other 18 columns match up and don't require SqlBulkCopyColumnMapping to be used. So after mapping my 2 columns and running my script I noticed that the only data that was copied between tables was the 2 columns that were mapped, not the other 18. Does this mean I have to map ALL columns so that all of the data can be copied or is there a way to tell SQLBulkCopy that the rest of the columns already match up and just copy them?

I am working in ASP.Net/VB and below is a sampling of the code I have


Using bulkCopy As SqlBulkCopy = New SqlBulkCopy(destinationConnection)
            bulkCopy.DestinationTableName = "dbo.WebProxyLog"
 
            Dim mapTime1 As New SqlBulkCopyColumnMapping("logTime", "logDate")
            bulkCopy.ColumnMappings.Add(mapTime1)
            Dim mapTime2 As New SqlBulkCopyColumnMapping("logTime", "logTime")
            bulkCopy.ColumnMappings.Add(mapTime2)
            bulkCopy.BulkCopyTimeout = 2000
 
            Try
                bulkCopy.WriteToServer(reader)
 
            Catch ex As Exception
                Console.WriteLine(ex.Message)
 
            Finally
                reader.Close()
            End Try
        End Using

Open in new window

Editors IDEsVisual Basic.NETASP.NET

Avatar of undefined
Last Comment
mascoloj

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Mohammed Nafadi

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
mascoloj

ASKER
Saw this at MSDN and was hoping for someway around it. Thanks
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck