【发布时间】:2014-08-11 11:57:36
【问题描述】:
我有一个 onChange TextBox 事件。当 textlength 为 22 时,应该显示一个 msgbox 并且应该建立一个数据库连接。
不幸的是,msgbox 没有出现,或者出现和消失的速度非常快。
不应该这样发生。我也尝试过使用 ApplicationModal 但这并没有改变任何东西。
示例代码:
Private Sub txt_Auftrag_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txt_Auftrag.TextChanged
If Len(txt_Auftrag.Text) = 22 Then 'txt_Auftrag.TextLength = 22 Then
MsgBox("In der If", MsgBoxStyle.ApplicationModal Or MsgBoxStyle.Critical Or MsgBoxStyle.OkOnly)
var_Aufrag = Mid(txt_Auftrag.Text, 15, 8)
'------------------------------------------SET dbConnection
Dim myConn As SqlConnection
Dim myCmdText As String
Try
Cursor.Current = Cursors.WaitCursor
myConn = New SqlConnection("Data Source=127.0.0.1;Initial Catalog=db;User ID=dbadm;Password=pw")
myConn.Open()
lbl_Auftrag_Value.Text = var_Aufrag
Cursor.Current = Cursors.Default
Catch ex As Exception
Cursor.Current = Cursors.Default
MsgBox("Verbindung zur Datenbank konnte nicht hergestellt werden. Kontaktieren Sie den Administrator. Fehlerbeschreibung: " & ex.Message)
var_Aufrag = Nothing
txt_Auftrag.Text = Nothing
Exit Sub
End Try
MsgBox("ConnGood")
【问题讨论】:
-
虽然提供示例代码很好,但您能提供您的实际代码吗?
-
你有没有使用调试器检查
If txt_Something.Text Length = 22中的代码是否被执行? -
如果 Statement 被执行,代码将(现在)在 catch 块中。还有一个MsgBox,这次被执行了……
-
正如@overmind 所说,您需要发布您正在使用的实际代码。我们都可以在您的帖子中看到印刷错误,这些错误会立即告诉我们它甚至不会像那样编译!如果你“登陆”
Catch,那有什么例外?? -
我使用了
If TextBoxName.Text.Length = 22 Then MsgBox("Hello", MsgBoxStyle.ApplicationModal) Else End If,对我来说效果很好。调试时会发生什么?