您好,登錄后才能下訂單哦!
VB.NET中怎么連接SAP,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
以下見代碼示例:
Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms
Imports System.Data.OleDb
Imports System.Xml
Public Class SAPConn
Public oFunction As Object ' SAP Functions
Public oConnection As Object ' SAP oConnection
Dim cmd As OleDbCommand
Dim SqlAd As OleDbDataAdapter
Dim sql As String
'測試連接的代碼
Private Sub BtnConnn_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles BtnConnn.Click
Try
oFunction = CreateObject("SAP.Functions.unicode")
oConnection = oFunction.Connection
oConnection.User = "CRMDEV69"
oConnection.Password = "654321"
oConnection.System = "CD2"
oConnection.ApplicationServer = "172.18.95.173"
oConnection.SystemNumber = 7
oConnection.Client = "164"
oConnection.Language = "ZH"
If oConnection.Logon(0, True) = True Then
MsgBox("連接成功!")
Else
MsgBox("連接失敗!")
End If
Catch ex As Exception
MsgBox(ex.ToString(), MsgBoxStyle.Information, "提示")
Return
End Try
End Sub
Private Sub Button1_Click(ByVal sender As
System.Object, ByVal e As System.EventArgs)
Handles Button1.Click
Dim GetCustomers As Object
Dim Customers As Object
Dim i As Integer
Dim sqlstr As String = ""
' 通過RFC接口遠程運行SAP內部函數ZCSMS_GET_HRINFO
' 賦要調用的SAP內建函數名
Try
GetCustomers = oFunction.Add("ZCSMS_GET_HRINFO")
'設置輸入參數并賦值
GetCustomers.Exports("BEGDAFROM") = ""
GetCustomers.Exports("BEGDATO") = ""
GetCustomers.Exports("MILL") = "7960"
GetCustomers.Exports("NUMBERFROM") = "0061500001"
GetCustomers.Exports("NUMBERTO") = "0061500200"
Customers = GetCustomers.Tables("THR")
If GetCustomers.Call Then
'循環插入到數據庫表中
For i = 1 To Customers.RowCount
sqlstr = "Insert into ghy_employee(MILL,
PERNR, NAME1, STEXT) values ('" & Customers
(i, "MILL") & "','" & Customers(i, "PERNR")
& "','" & Customers(i, "NAME1") & "','"
& Customers(i, "STEXT") & "' )"
Config.ExecAccess(sqlstr)
Next i
MsgBox("獲取數據成功")
Else
MsgBox(" 搜索出錯! 出錯信息: " +
GetCustomers.exception)
End If
Catch ex As Exception
MsgBox(ex.ToString)
Return
End Try
End Sub
'通過GridView顯示數據
Private Sub Button2_Click(ByVal sender As System.
Object, ByVal e As System.EventArgs) Handles
Button2.Click
sql = "select * from ghy_employee "
SqlAd = New OleDbDataAdapter(sql, oConn)
DS.Clear()
If DS.Tables.Contains("ghy_employee") Then
DS.Tables.Remove("ghy_employee")
End If
SqlAd.Fill(DS, "ghy_employee")
DvInvoice.DataSource = DS.Tables("ghy_employee").
DefaultView
DvInvoice.Refresh()
DvInvoice.ClearSelection()
DvInvoice.Columns("MILL").HeaderText = "工廠"
DvInvoice.Columns("PERNR").HeaderText = "員工編號"
DvInvoice.Columns("NAME1").HeaderText = "員工姓名"
DvInvoice.Columns("STEXT").HeaderText = "員工部門"
End Sub
End Class
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注億速云行業資訊頻道,感謝您對億速云的支持。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。