我通过 COM 连接到 SAP,使用拖入表单的 ActiveX 控件。在VB6中我写:
Private Sub Form_Terminate()
SAPBAPIControl.Connection.Logoff
End Sub
Private Sub SAPLogonControl_Click()
Set SAPBAPIControl.Connection = SAPLogonControl.NewConnection
SAPBAPIControl.Connection.Client = "100"
If SAPBAPIControl.Connection.Logon(0, False) Then
MsgBox SAPBAPIControl.Connection.IsConnected
End If
End Sub
在 VB.NET 2010 中,我写道:
Public Class MainForm
Private Sub MainForm_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
AxSAPBAPIControl1.Connection.Logoff()
End Sub
Private Sub AxSAPLogonControl1_ClickEvent(sender As Object, e As System.EventArgs) Handles AxSAPLogonControl1.ClickEvent
AxSAPBAPIControl1.Connection = AxSAPLogonControl1.NewConnection()
AxSAPBAPIControl1.Connection.Client = "100"
If AxSAPBAPIControl1.Connection.Logon(0, False) Then
MsgBox(AxSAPBAPIControl1.Connection.IsConnected)
End If
End Sub
End Class
最后得到:
Eine Ausnahme (erste Chance) des Typs "System.AccessViolationException" ist in mscorlib.dll aufgetreten。在 .Client = "100"
VB6 可以正常工作。
有谁知道如何将连接对象传输到 VB.NET 中的其他类
谢谢您的帮助。