VB.NET中怎么连接SAP
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.ClickTry
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.ClickDim 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.Clicksql = "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").
DefaultViewDvInvoice.Refresh()
DvInvoice.ClearSelection()
DvInvoice.Columns("MILL").HeaderText = "工厂"
DvInvoice.Columns("PERNR").HeaderText = "员工编号"
DvInvoice.Columns("NAME1").HeaderText = "员工姓名"
DvInvoice.Columns("STEXT").HeaderText = "员工部门"
End Sub
End Class
看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注创新互联行业资讯频道,感谢您对创新互联的支持。
本文名称:VB.NET中怎么连接SAP
URL地址:http://scyanting.com/article/jijshe.html