深圳全飞鸿

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 674|回复: 1
打印 上一主题 下一主题

VB调用mysql数据库存储过程SP的方法

[复制链接]

800

主题

1379

帖子

7704

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7704
跳转到指定楼层
楼主
发表于 2019-5-4 13:23:23 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
本帖最后由 zhgc 于 2019-6-25 10:19 编辑

VB调用mysql数据库SP的方法
VB调用mysql数据库SP的方法
http://www.nagomes.com/disc/foru ... ad&tid=22&fromuid=6

VB对mysql的SQL增删改查
http://www.nagomes.com/disc/foru ... d&tid=109&fromuid=6



  1. Public cn As ADODB.Connection
  2. Dim spcmd As New Command


  3.   c_ReturnMessage = "ERROR"
  4.   spcmd.ActiveConnection = cn
  5.   If spcmd.Parameters.Count = 0 Then
  6.     spcmd.Parameters.Append spcmd.CreateParameter("@x", adVarChar, adParamOutput, 200, "")
  7.   End If

  8.   spcmd.CommandType = adCmdText
  9.   spcmd.CommandText = "call SMT.G_SCADA_I1PORT_KB('" & data & "','" & gw28_list(c_gw28_index).station_no & "',@x)"
  10.   spcmd.Execute
  11.   Set rs = cn.Execute("select @x")
  12.   If Not rs.EOF Then
  13.     c_ReturnMessage = rs(0).Value
  14.   End If
  15.   rs.Close
  16.   Set rs = Nothing
复制代码


回复

使用道具 举报

800

主题

1379

帖子

7704

积分

版主

Rank: 7Rank: 7Rank: 7

积分
7704
沙发
 楼主| 发表于 2019-5-4 16:57:14 | 只看该作者
以上方法并不是真正在调用SP, 请参考以下方法:


  1. Public Function callsp(Mydata As String, gw28index) As String
  2. Dim strsql As String
  3. Dim rs As Recordset
  4. Dim sp As String
  5. Dim call_sp As ADODB.Command


  6. If gw_list(gwindex).sp = "" Then
  7.     callsp = "SCADA CONFIG ERROR"
  8.     Exit Function
  9. End If

  10. Set call_sp = New ADODB.Command
  11. With call_sp
  12.    .ActiveConnection = cn
  13.    .CommandType = adCmdStoredProc
  14.    .CommandText = gw_list(gwindex).sp
  15.    .Parameters(0) = Mydata
  16.    .Parameters(1) = gw_list(gwindex).line_name
  17.    .Parameters(2) = gw_list(gwindex).station_name
  18.    .Execute
  19.    callsp = .Parameters(3)
  20.    
  21. End With

  22. End Function
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

QQ|Archiver|手机版|小黑屋|nagomes  

GMT+8, 2025-5-5 01:35 , Processed in 0.021776 second(s), 20 queries .

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表