这是一个登录代码,它还假设验证此人是“管理员”还是“工作人员”。
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”的变量进行比较,但事实并非如此。
一些帮助将不胜感激,谢谢。