2012-07-22 144 views
1

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

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 

回答

2

有在你的代码回路和退出条件细看...在什么情况下不循环退出,否则会发生什么

一般来说,你需要在这里发挥出并覆盖所有的情况,但你已经知道的情况:??你的用户输入不是在数据库和应用程序冻结这应该。提供足够的提示以找到原因。

+0

因此...你墨水我可以使用退出时,并把和如果?你认为它工作? – DFabeiro 2012-07-25 16:16:56

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