Earn Extra Money

Login Form (WPF) with MySQL




Private Sub btnSubmit_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles btnSubmit.Click
Dim sqlconn As New MySqlConnection("Server=localhost;User Id=root;Password='';Database=risenlordmember")
If cbmode.Text = "Administrator" Then

Try

Dim sqlquery As String = "SELECT * From password WHERE username ='" & txtUsername.Text & "';"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As MySqlCommand = New MySqlCommand


sqlconn.Open()

command.CommandText = sqlquery
command.Connection = sqlconn
adapter.SelectCommand = command
data = command.ExecuteReader



While data.Read()
If data.HasRows() = True Then
If data(2).ToString = txtPassword.Password Then
MsgBox("Login Successful!", vbInformation, "Welcome Admin")

Else

Dim Notification As String
Notification = MsgBox("Wrong Username/Password, Try again?", vbOKCancel + vbCritical, "Failed!")
txtUsername.Clear()
txtPassword.Clear()

If Notification = vbOK Then

sqlconn.Open()

ElseIf Notification = vbCancel Then
Me.Close()

End If

End If

End If

End While


sqlconn.Close()








Catch ex As Exception

Finally
sqlconn.Dispose()

End Try



ElseIf cbmode.Text = "Member" Then

Try

Dim sqlquery As String = "SELECT * From password WHERE member_id ='" & txtUsername.Text & "';"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As MySqlCommand = New MySqlCommand


sqlconn.Open()

command.CommandText = sqlquery
command.Connection = sqlconn
adapter.SelectCommand = command
data = command.ExecuteReader



While data.Read()
If data.HasRows() = True Then
If data(2).ToString = txtPassword.Password Then
MsgBox("Login Successful!", vbInformation, "Welcome Member")


Else

Dim Notification As String
Notification = MsgBox("Wrong Username/Password, Try again?", vbOKCancel + vbCritical, "Failed!")
txtUsername.Clear()
txtPassword.Clear()


If Notification = vbOK Then

sqlconn.Open()

ElseIf Notification = vbCancel Then
Me.Close()

End If

End If

End If

End While


sqlconn.Close()

Catch ex As Exception

Finally
sqlconn.Dispose()

End Try

End If


End Sub

No comments:

Post a Comment