VB.NET中怎么連接SAP,很多新手對此不是很清楚,為了幫助大家解決這個難題,下面小編將為大家詳細講解,有這方面需求的人可以來學習下,希望你能有所收獲。
成都創(chuàng)新互聯公司堅持“要么做到,要么別承諾”的工作理念,服務領域包括:網站制作、成都網站設計、企業(yè)官網、英文網站、手機端網站、網站推廣等服務,滿足客戶于互聯網時代的扎賚諾爾網站設計、移動媒體設計的需求,幫助企業(yè)找到有效的互聯網解決方案。努力成為您成熟可靠的網絡建設合作伙伴!
以下見代碼示例:
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
'循環(huán)插入到數據庫表中
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
看完上述內容是否對您有幫助呢?如果還想對相關知識有進一步的了解或閱讀更多相關文章,請關注創(chuàng)新互聯行業(yè)資訊頻道,感謝您對創(chuàng)新互聯的支持。