I'm quite a newbie in asp.net and/or VB, I'm trying to make a simple mysql authentication login page on my asp.net webform. I'm getting the same error every time I try to run my page and I have no idea how to solve it. Here is the error:
Error BC30506 Handles clause requires a WithEvents variable defined in the containing type or one of its base types. Test1 C:UsersPCDesktopTest1AccountLogin.aspx.vb 10 Active
Here is my codebehind for the said error:
Protected Sub Login_Authenticate(sender As Object, e As AuthenticateEventArgs) Handles Login.Authenticate
Dim Username As String = Login.UserName
Dim password As String = Login.Password
Dim SQLCommand As String = "SELECT level FROM users WHERE (username= '" &
Username & "' AND pw = '" & password & "')"
Dim level As String
Dim con As MySqlConnection = New MySqlConnection()
con.ConnectionString = System.Configuration.ConfigurationManager.ConnectionStrings("test").ToString()
Dim cmd As MySqlCommand = New MySqlCommand(SQLCommand, con)
con.Open()
If cmd.ExecuteScalar() = Nothing Then
level = ""
Else
level = cmd.ExecuteScalar().ToString()
End If
con.Close()
If level = "B" Or level = "G" Then
Session("Level") = level
Session("User") = Username
FormsAuthentication.RedirectFromLoginPage(Username, False)
Else
Login.FailureText = "Try Again"
End If
End Sub
I first thought it was because I used = instead of 'Is' in If cmd.ExecuteScalar() = Nothing Then
But changing it doesn't really affect it. Can anyone help me out with this? Thanks in advance, DeBakker
Aucun commentaire:
Enregistrer un commentaire