如何在VB6中检查SQL语句是否成功执行

时间:2015-09-18 04:24:06

标签: php sql vb6

我有这些代码

Call Connection

Dim SQLInsert As String

SQLInsert = "INSERT INTO `Admin` (" & _
                "`kode`," & _
                "`nama`," & _
                "`password`," & _
                "`level`" & _
            ") VALUES (" & _
                "'" & Text1.Text & "', " & _
                "'" & Text2.Text & "', " & _
                "'" & Text3.Text & "', " & _
                "'" & Combo1.Text & "'" & _
            ")"

conn.Execute SQLInsert

MsgBox "Insert Succeed"

如何从上面的执行语句中获取返回值,无论代码成功还是失败......

我希望像PHP一样获得返回值

<?php
    $result = mysqli_query($link, $sql);
    if ($result)
       //executing other code

我怎么能在VB6中这样做?感谢

2 个答案:

答案 0 :(得分:1)

阅读ON ERROR声明。它允许在VB中处理异常。

Dim SQLInsert As String

ON ERROR GOTO ErrorHandler

SQLInsert = "INSERT INTO `Admin` (" & _
                "`kode`," & _
                "`nama`," & _
                "`password`," & _
                "`level`" & _
            ") VALUES (" & _
                "'" & Text1.Text & "', " & _
                "'" & Text2.Text & "', " & _
                "'" & Text3.Text & "', " & _
                "'" & Combo1.Text & "'" & _
            ")"

conn.Execute SQLInsert

MsgBox "Insert Succeed" 
Exit Sub

ErrorHandler: 
 Msg = "Error # " & Str(Err.Number) & " was generated by " &
        Err.Source & ControlChars.CrLf & Err.Description
  MsgBox(Msg, MsgBoxStyle.Information, "Error")
Exit Sub

答案 1 :(得分:1)

应该有可能让'行影响'值回来。请阅读此Microsoft链接:

https://msdn.microsoft.com/en-us/library/ms681559(v=vs.85).aspx

您需要添加“adExecuteNoRecords”选项,“备注”一章