0
我的數據庫:VB.NET管理員和標準用戶登錄失敗
username | password | user_ty
roger | 54321 | admin
maire | 12345 | user
我無法登錄到不同的形式。 它只是顯示「不正確的用戶名或密碼」。爲兩個用戶名。
Try
Dim con As New SqlConnection("Data Source=192.168.10.3;Initial Catalog=IT_INV;user id=sa;[email protected]")
con.Open()
Dim rs As New SqlCommand("SELECT * FROM [user] WHERE [email protected] AND [email protected]", con)
Dim usernameParam As New SqlParameter("@username", Me.TextBox1.Text)
Dim passwordParam As New SqlParameter("@password", Me.TextBox2.Text)
rs.Parameters.Add(usernameParam)
rs.Parameters.Add(passwordParam)
Dim sqlRead As SqlDataReader = rs.ExecuteReader
If sqlRead.HasRows Then
If sqlRead.Read = True Then
If sqlRead("user_ty") = "admin" Then
form2.Show()
Me.Hide()
ElseIf sqlRead("user_ty") = "user" Then
form3.Show()
Me.Hide()
Else
MessageBox.Show("Incorrect Username or Password.", "Login Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
TextBox1.Text = ""
TextBox2.Text = ""
End If
End If
End If
Catch ex As Exception
MessageBox.Show(ex.Message)
End Try
[如何問一個問題(https://stackoverflow.com/help/how-to-ask),[如何發佈代碼] (https://stackoverflow.com/help/mcve) – specializt