大家可能对于VB.NET的开发能力非常感兴趣。因为它的应用能够帮助我们带来一个良好的功能强大的开发平台。VB.NET连接SAP中只是把读取出来的内容存放在数据库中,然后利用GridView显示出来。 当然可以直接存入DataTable或DataSet中直接显示出来。#t#
从策划到设计制作,每一步都追求做到细腻,制作可持续发展的企业网站。为客户提供成都网站制作、网站建设、外贸网站建设、网站策划、网页设计、域名申请、雅安服务器托管、网络营销、VI设计、 网站改版、漏洞修补等服务。为客户提供更好的一站式互联网解决方案,以客户的口碑塑造优易品牌,携手广大客户,共同发展进步。
以下见代码示例:
- 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
以上两种写法都是利用创建组件OCX的方式进行, 通过调用类的方法进行也可以实现。 缺点是中文无法正常显示。
网站标题:VB.NET连接SAP实际应用方法介绍
本文链接:http://www.gawzjz.com/qtweb/news47/162347.html
网站建设、网络推广公司-创新互联,是专注品牌与效果的网站制作,网络营销seo公司;服务项目有等
广告
声明:本网站发布的内容(图片、视频和文字)以用户投稿、用户转载内容为主,如果涉及侵权请尽快告知,我们将会在第一时间删除。文章观点不代表本网站立场,如需处理请联系客服。电话:028-86922220;邮箱:631063699@qq.com。内容未经允许不得转载,或转载时需注明来源:
创新互联