深圳全飞鸿

标题: VB调用mysql数据库存储过程SP的方法 [打印本页]

作者: zhgc    时间: 2019-5-4 13:23
标题: VB调用mysql数据库存储过程SP的方法
本帖最后由 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
复制代码



作者: zhgc    时间: 2019-5-4 16:57
以上方法并不是真正在调用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
复制代码





欢迎光临 深圳全飞鸿 (http://www.nagomes.com/disc/) Powered by Discuz! X3.2