1

我的登录有问题...好吧,让我解释一下我的问题,问题是我想创建一个有限制的登录,我有一些文本框,绑定源属性更改为我的数据库。但是当我输入不在数据库中的东西时程序冻结了,我会发布我的代码,希望你能帮助我(=

Private Sub KryptonButton1_Click(ByVal sender As System.Object, 
                                 ByVal e As System.EventArgs) 
            Handles KryptonButton1.Click

    If txtUser.Text <> UserTextBox.Text Then
        While txtUser.Text <> UserTextBox.Text
            Me.UsuarioContraseñaBindingSource.MoveNext()
        End While
        If txtUser.Text = UserTextBox.Text Then
            KryptonMessageBox.Show("Welcome")
        Else
            KryptonMessageBox.Show("Error")
        End If
    End If

End Sub
4

2 回答 2

2

仔细查看代码中的循环及其退出条件……循环在什么情况下退出?否则会发生什么?

一般来说,您需要播放并涵盖所有场景,但您已经知道这里的场景:您的用户输入不在数据库中并且应用程序冻结。这应该提供足够的提示来找到原因。

于 2012-07-23T13:33:52.793 回答
0
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
        If txt_user.Text <> vbNullString And txt_pass.Text <> vbNullString Then
            Dim chkcmd As New SqlCommand("select * from users where username = '" & txt_user.Text & "' and password = '" & txt_pass.Text & "'", con)
            If con.State = ConnectionState.Open Then con.Close()
            con.Open()
            Dim chkval As SqlDataReader = chkcmd.ExecuteReader
            If chkval.Read = True Then
                Me.Hide()
                Form2.Show()
            Else
                MsgBox("Invalid key to login!", MsgBoxStyle.Exclamation, "Message")
                txt_pass.Clear()
                txt_user.Clear()
                txt_user.Select()
            End If
            con.Close()
        End If
    End Sub
于 2014-01-07T03:56:06.397 回答