先在sql server 的数据转换服务(DTS)中新建DTS包,保存为*.dts文件,VB中调用一下即可。
注:工程--引用---Microsoft DTSPackage ....选中。
--------------------------------------------------
Private Sub RunPackage(ByVal S As String)'S is FileName
Dim objPackage As DTS.Package2
Dim objStep As DTS.Step
Dim objTask As DTS.Task
Dim objExecPkg As DTS.ExecutePackageTask
'On Error GoTo PackageError
Set objPackage = New DTS.Package
Set mobjPkgEvents = objPackage
objPackage.FailOnError = True
'Create the step and task. Specify the package to be run, and link the step to the task.
Set objStep = objPackage.Steps.New
Set objTask = objPackage.Tasks.New("DTSExecutePackageTask")
Set objExecPkg = objTask.CustomTask
With objExecPkg
.PackagePassword = ""
.FileName = S
.Name = "ExecPkgTask"
End With
With objStep
.TaskName = objExecPkg.Name
.Name = "ExecPkgStep"
.ExecuteInMainThread = True
End With
objPackage.Steps.Add objStep
objPackage.Tasks.Add objTask
'Run the package and release references.
objPackage.Execute
Set objExecPkg = Nothing
Set objTask = Nothing
Set objStep = Nothing
Set mobjPkgEvents = Nothing
objPackage.UnInitialize
End Sub
标签:objExecPkg,VB,Set,objTask,server,objStep,objPackage,sql,DTS From: https://blog.51cto.com/u_3649463/6205940