The revised code for the method is:
' copy a data table from one db to another
Public Sub CopyTable(ByVal iSourceServerName As String,
ByVal iTargetServerName As String,
ByVal iSrcDatabase As String,
ByVal iTargerDatabase As String,
ByVal iTblName As String,
ByVal CopyData As Boolean,
<Out> ByRef iRetMsg As String)
Dim srcsrv = New Server(iSourceServerName)
Dim srcdb As Database = srcsrv.Databases(iSrcDatabase)
Dim iTbl = srcdb.Tables(iTblName) ' the table to transfer
Dim targetsrv = New Server(iTargetServerName)
Dim targetdb As New Database(targetsrv, iTargerDatabase)
Dim trans As New Transfer()
With trans
.Database = srcdb
.DestinationServer = iTargetServerName
.DestinationDatabase = iTargerDatabase
.DestinationLoginSecure = True
.ObjectList.Add(iTbl) ' only transfer the specified table
.CopyAllObjects = False
.CopyAllTables = False
.CopySchema = True
.CopyData = CopyData
With .Options
.ContinueScriptingOnError = True
.DriAllKeys = True
.WithDependencies = False
.DriAll = False
.DriDefaults = True
.DriIndexes = True
.DriPrimaryKey = True
.DriUniqueKeys = True
.DriForeignKeys = False
End With
End With
Try
trans.TransferData()
Catch ex As Exception
iRetMsg = ex.ToString
End Try
End Sub