vb.net
1,引用Microsoft.SqlServer.ManagedDTS組件
2,調用Imports Microsoft.SqlServer.Dts.Runtime命名空間
3,代碼:
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
Public Function ExecutePackage()Function ExecutePackage() As Integer
Dim pkg As String = "E:\project\DropShipment\Code\TXTImport\TXTImport\Package.dtsx"
Dim app As Application = New Application()
Dim p As Package = app.LoadPackage(pkg, Nothing)
'p.InteractiveMode = True
Dim vir As Variables = p.Variables
' vir("用户::PackageID").Value = 4
If p.Execute(Nothing, vir, Nothing, Nothing, Nothing) = DTSExecResult.Success Then
Return 0
Else
Return 1
End If
End Function
C#
![](/Images/OutliningIndicators/ContractedBlock.gif)
Code
public int ExecutePackage()
{
string pkg = @"E:\project\DropShipment\Code\TXTImport\TXTImport\Package.dtsx";
Application app = new Application();
Package p = app.LoadPackage(pkg, null);
Variables vir=p.Variables;
//p.Execute(null, vir, null, null, null)
if (p.Execute() == DTSExecResult.Success)
{
Label1.Text = "success";
return 0;
}
else
{
Label1.Text = "error";
return 1;
}
}