这是一个登录代码,它还假设验证此人是否只是“管理员”或只是“员工”。
Private Sub btnopenapplication_Click(sender As System.Object, e As System.EventArgs) Handles btnlogin.Click
Dim reader As SqlDataReader
Dim verify_account_type As String
Dim sqlstatement As SqlCommand = New SqlCommand
sqlstatement.Connection = connection
Try
sqlstatement.CommandText = "Select account_username, account_password, account_type " &
"from login_account where account_username='" & txtusername.Text & "' and account_password='" & txtpassword.Text & "'"
reader = sqlstatement.ExecuteReader()
If (reader.Read()) Then
Dim account_type As String = "Administrator"
verify_account_type = CStr(reader("account_type").ToString)
If String.Compare(account_type, verify_account_type) = 0 Then
application_form.Show()
Me.Visible = False
Else
MsgBox("you are not an administrator")
End If
sqlstatement.Dispose()
reader.Close()
Else
MsgBox("Invalid")
End If
reader.Close()
Catch ex As Exception
MsgBox(vbCrLf & ex.Message)
End Try
End Sub
这似乎是失败的地方
If String.Compare(account_type, verify_account_type) = 0 Then
application_form.Show()
Me.Visible = False
Else
MsgBox("you are not an administrator")
End If
登录有效,但无法进行比较。基本上我有一个包含帐户类型(“管理员”和“员工”)的数据库。它假设读取 account_type 并将值放入一个变量中,该变量会将其与另一个值为“Administrator”或“Staff”的变量进行比较,但事实并非如此。
一些帮助将不胜感激,谢谢。