我有一个登录问题...好吧,让我解释一下我的问题,问题是我想创建一个带有限制的登录,我有一些文本框,绑定源属性已更改为我的数据库。但是当我输入不在DataBase中的程序时程序被冻结,我会发布我的代码,希望你能帮助我(=
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
答案 0 :(得分:2)
仔细查看代码中的循环及其退出条件......在什么情况下循环退出?否则会发生什么?
通常,您需要播放并覆盖所有场景,但您已经知道此处的场景:您的用户输入不在数据库中,应用程序冻结。这应该提供足够的提示来找到原因。
答案 1 :(得分: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