03-26-2013, 11:51 AM
hello guys,
Following the tutorials of brandonio i made a login form and tried to give some additional features to it.
Here the code of the login form:
I have added the features to say the user doesn't exist in the login form....but it works great with the off_members but when using the reg_members after login i get the error of user doesn't exist many times....
Please help me how can I solve this problem and what is the solved code.....
Brandonio bro needs your help.....
Following the tutorials of brandonio i made a login form and tried to give some additional features to it.
Here the code of the login form:
Code:
Imports MySql.Data.MySqlClient
Public Class loginForm
Public conn As MySqlConnection
Private Sub loginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles loginButton.Click
conn = New MySqlConnection(ServerString)
Select Case ComboBox1.Text
Case "Normal Member"
If txtUsername.Text = Nothing Or txtPassword.Text = Nothing Then
MsgBox("Please fill up all the fields.", MsgBoxStyle.Information, "Error")
Else
Me.Cursor = Cursors.AppStarting
Try
conn.Open()
Dim sqlquery As String = "SELECT * FROM reg_members"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = sqlquery
command.Connection = conn
adapter.SelectCommand = command
data = command.ExecuteReader
While data.Read()
If data.HasRows() = True Then
If Not data(1).ToString = txtUsername.Text Then
MsgBox("Login Failed. Account doesn't exist. Please register to log in.", MsgBoxStyle.Critical, "Error")
Else
If data(2).ToString = txtPassword.Text Then
MsgBox("You have successfully logged in.", MsgBoxStyle.Information, "Login Successful")
Me.Close()
normalMemberForm.Show()
Else
MsgBox("Login Failed. Incorrect password. Please try again.", MsgBoxStyle.Critical, "Error")
End If
End If
Else
MsgBox("Login Failed. Incorrect password. Please try again.", MsgBoxStyle.Critical, "Error")
End If
End While
Catch ex As Exception
End Try
End If
Case "Official Member"
If txtUsername.Text = Nothing Or txtPassword.Text = Nothing Then
MsgBox("Please fill up all the fields.", MsgBoxStyle.Information, "Error")
Else
Me.Cursor = Cursors.AppStarting
Try
conn.Open()
Dim sqlquery As String = "SELECT * FROM off_members"
Dim data As MySqlDataReader
Dim adapter As New MySqlDataAdapter
Dim command As New MySqlCommand
command.CommandText = sqlquery
command.Connection = conn
adapter.SelectCommand = command
data = command.ExecuteReader
While data.Read()
If data.HasRows() = True Then
If Not data(1).ToString = txtUsername.Text Then
MsgBox("Login Failed. Account doesn't exist. Please register to log in.", MsgBoxStyle.Critical, "Error")
Else
If data(2).ToString = txtPassword.Text Then
MsgBox("You have successfully logged in.", MsgBoxStyle.Information, "Login Successful")
Me.Close()
officialMemberForm.Show()
Else
MsgBox("Login Failed. Incorrect password. Please try again.", MsgBoxStyle.Critical, "Error")
End If
End If
Else
MsgBox("Login Failed. Incorrect password. Please try again.", MsgBoxStyle.Critical, "Error")
End If
End While
Catch ex As Exception
End Try
End If
End Select
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
loginButton.Enabled = True
loginButton.Select()
End Sub
End Class
I have added the features to say the user doesn't exist in the login form....but it works great with the off_members but when using the reg_members after login i get the error of user doesn't exist many times....
Please help me how can I solve this problem and what is the solved code.....
Brandonio bro needs your help.....