代码之家  ›  专栏  ›  技术社区  ›  NewProg

ErrorHandler仍显示错误

vb6
  •  -1
  • NewProg  · 技术社区  · 10 年前

    当我键入text1但它是错误的时,错误显示,但命令2被启用。当我输入正确的数据库名称时。错误仍然显示,command2再次启用。我不知道发生了什么。

    Private Sub Command1_Click()
    
         conAddStudent.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID= 123 ;Initial Catalog=" & Text1.Text & "  ;Data Source=COM1\SQLEXPRESS;password= 123"
    
          On Error GoTo err
         command2.Enabled = True
    err:
         MsgBox "none"
    
         Exit Sub
    
    End Sub
    
    1 回复  |  直到 10 年前
        1
  •  1
  •   Vincent James    10 年前

    您需要在错误标签之前向上移动Exit Sub,以便它在正常运行时触发错误之前退出。

    Private Sub Command1_Click()
    
      conAddStudent.ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID= 123 ;Initial Catalog=" & Text1.Text & "  ;Data   Source=COM1\SQLEXPRESS;password= 123"
    
      If Text2.Text = "Valid Name" Then
          Text2.Enabled = True
      Else
          MsgBox "none"
      End If
    
    End Sub