2012-07-22 135 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