温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

VB.NET中怎么连接SAP

发布时间:2021-07-19 16:04:19 来源:亿速云 阅读:154 作者:Leah 栏目:编程语言

VB.NET中怎么连接SAP,很多新手对此不是很清楚,为了帮助大家解决这个难题,下面小编将为大家详细讲解,有这方面需求的人可以来学习下,希望你能有所收获。

以下见代码示例:

  1. Imports System  

  2. Imports System.Collections.Generic  

  3. Imports System.ComponentModel  

  4. Imports System.Data  

  5. Imports System.Drawing  

  6. Imports System.Text  

  7. Imports System.Windows.Forms  

  8. Imports System.Data.OleDb  

  9. Imports System.Xml  

  10. Public Class SAPConn  

  11. Public oFunction As Object ' SAP Functions  

  12. Public oConnection As Object ' SAP oConnection  

  13. Dim cmd As OleDbCommand  

  14. Dim SqlAd As OleDbDataAdapter  

  15. Dim sql As String  

  16. '测试连接的代码  

  17. Private Sub BtnConnn_Click(ByVal sender As 
    System.Object, ByVal e As System.EventArgs) 
    Handles BtnConnn.Click  

  18. Try  

  19. oFunction = CreateObject("SAP.Functions.unicode")  

  20. oConnection = oFunction.Connection  

  21. oConnection.User = "CRMDEV69" 

  22. oConnection.Password = "654321" 

  23. oConnection.System = "CD2" 

  24. oConnection.ApplicationServer = "172.18.95.173" 

  25. oConnection.SystemNumber = 7 

  26. oConnection.Client = "164" 

  27. oConnection.Language = "ZH" 

  28. If oConnection.Logon(0, True) = True Then  

  29. MsgBox("连接成功!")  

  30. Else  

  31. MsgBox("连接失败!")  

  32. End If  

  33. Catch ex As Exception  

  34. MsgBox(ex.ToString(), MsgBoxStyle.Information, "提示")  

  35. Return  

  36. End Try  

  37. End Sub  

  38. Private Sub Button1_Click(ByVal sender As 
    System.Object, ByVal e As System.EventArgs) 
    Handles Button1.Click  

  39. Dim GetCustomers As Object  

  40. Dim Customers As Object  

  41. Dim i As Integer  

  42. Dim sqlstr As String = "" 

  43. ' 通过RFC接口远程运行SAP内部函数ZCSMS_GET_HRINFO  

  44. ' 赋要调用的SAP内建函数名  

  45. Try  

  46. GetCustomers = oFunction.Add("ZCSMS_GET_HRINFO")  

  47. '设置输入参数并赋值  

  48. GetCustomers.Exports("BEGDAFROM") = ""  

  49. GetCustomers.Exports("BEGDATO") = ""  

  50. GetCustomers.Exports("MILL") = "7960"  

  51. GetCustomers.Exports("NUMBERFROM") = "0061500001"  

  52. GetCustomers.Exports("NUMBERTO") = "0061500200"  

  53. Customers = GetCustomers.Tables("THR")  

  54. If GetCustomers.Call Then  

  55. '循环插入到数据库表中  

  56. For i = 1 To Customers.RowCount  

  57. sqlstr = "Insert into ghy_employee(MILL, 
    PERNR, NAME1, STEXT) values ('"
     & Customers
    (i, "MILL") & "','" & Customers(i, "PERNR") 
    & "','" & Customers(i, "NAME1") & "','" 
    & Customers(i, "STEXT") & "' )"  

  58. Config.ExecAccess(sqlstr)  

  59. Next i  

  60. MsgBox("获取数据成功")  

  61. Else  

  62. MsgBox(" 搜索出错! 出错信息: " + 
    GetCustomers.exception)  

  63. End If  

  64. Catch ex As Exception  

  65. MsgBox(ex.ToString)  

  66. Return  

  67. End Try  

  68. End Sub  

  69. '通过GridView显示数据  

  70. Private Sub Button2_Click(ByVal sender As System.
    Object, ByVal e As System.EventArgs) Handles 
    Button2.Click  

  71. sql = "select * from ghy_employee " 

  72. SqlAd = New OleDbDataAdapter(sql, oConn)  

  73. DS.Clear()  

  74. If DS.Tables.Contains("ghy_employee") Then  

  75. DS.Tables.Remove("ghy_employee")  

  76. End If  

  77. SqlAd.Fill(DS, "ghy_employee")  

  78. DvInvoice.DataSource = DS.Tables("ghy_employee").
    DefaultView  

  79. DvInvoice.Refresh()  

  80. DvInvoice.ClearSelection()  

  81. DvInvoice.Columns("MILL").HeaderText = "工厂" 

  82. DvInvoice.Columns("PERNR").HeaderText = "员工编号" 

  83. DvInvoice.Columns("NAME1").HeaderText = "员工姓名" 

  84. DvInvoice.Columns("STEXT").HeaderText = "员工部门" 

  85. End Sub  

  86. End Class 

看完上述内容是否对您有帮助呢?如果还想对相关知识有进一步的了解或阅读更多相关文章,请关注亿速云行业资讯频道,感谢您对亿速云的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI