Click here to Skip to main content
15,938,218 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys,ive been working on trying to create a login form.
ms Access side:
-used a logininfo.mdb database with columns :username,password,job
vb 2008 side:
-login form with clerk rad button,manager rad button,username text box,password textbox and login button
now the challenge im having is that only the "Clerk" can login properly,ive used the same code for "Manager"
but just swapped the variables.however "manager" cant login
pls pls pls help asap,gotta submit this system soon

here's the code:
VB
 Imports System.Data.OleDb
Public Class database
    Public Sub login()
        Dim con As New OleDb.OleDbConnection
        con.ConnectionString = "PROVIDER=Microsoft.JET.OLEDB.4.0;Data Source = ..\logininfo.mdb"
        Dim cmd As OleDbCommand = New OleDbCommand("SELECT job,username,password FROM login where username=? and password=?", con)

        cmd.Parameters.AddWithValue("username", Form1.TextBox1.Text)
        cmd.Parameters.AddWithValue("password", Form1.TextBox2.Text)

        Try
            con.Open()
            Dim read As OleDbDataReader = cmd.ExecuteReader()

            If read.HasRows Then
                read.Read()

                ''validate clerk
                If Form1.TextBox1.Text.ToLower() = read.Item("username").ToString And Form1.TextBox2.Text.ToLower = read.Item("password").ToString And Form1.rdbclerk.Checked Then
                    MsgBox("Login successful")
                    frmclk.ShowDialog()
                    Form1.Hide()

                Else
                    If String.IsNullOrEmpty(Form1.TextBox1.Text) Xor String.IsNullOrEmpty(Form1.TextBox2.Text) Xor Form1.rdbclerk.Checked = False _
                                                               Xor Form1.rdbmgr.Checked Then
                        MsgBox("emp Login unsuccessful,pls type the correct details  and select the correct usertype")
                    End If
                End If

                'validate manager
                If Form1.TextBox1.Text.ToLower() = read.Item("username").ToString And Form1.TextBox2.Text.ToLower = read.Item("password").ToString And Form1.rdbmgr.Checked Then
                    MsgBox("Login successful")
                    frmclk.ShowDialog()
                    Form1.Hide()

                Else
                    If String.IsNullOrEmpty(Form1.TextBox1.Text) Xor String.IsNullOrEmpty(Form1.TextBox2.Text) Xor Form1.rdbclerk.Checked = False _
                                                               Xor Form1.rdbclerk.Checked Then
                        MsgBox("emp Login unsuccessful,pls type the correct details  and select the correct usertype")
                    End If
                End If

            Else
                MsgBox("Login unsuccessful,no connection")
            End If

            read.Close()
        Catch ex As Exception
            MessageBox.Show(ex.Message)
        Finally
            con.Close()
        End Try


    End Sub
End Class


[EDIT]Tags added - LOSMAC[/EDIT]
Posted
Updated 21-Mar-12 6:04am
v2

1 solution

There are several issues:

1. Very difficult to read.
2. Unnecessary checking after a query
etc.

Here are some suggestions:

1. Validate the input before doing anything in the function. Exit the function if the input is invalid.

2. If the reader returns records, the user name and password already match, you are done. No need to check further. Based on the value of the radio button, open the required form.

3. You may want to ensure that the value of the job field returned by the query and the value of the selected radio button match. Alternately, add the job as a parameter to the query.

4. If the reader does not return records, either the username/password is wrong. Display message and exit function.
 
Share this answer
 
Comments
RhandzuM 22-Mar-12 5:34am    
thanx for your enlightenment.the thing is im a beginner and have had unsuccessful trials in comparing the selection of the radio button and the value of the job type in the database because it gives and error that the radio button returns boolean and can not be matched with the string value of job in the database. would you pls help with the missing code,just copy the whole code and paste to yo IDE.
shreekar 22-Mar-12 14:02pm    
No problem - please post the code from the attempts you have made to compare the values and I am sure you will get help.

Improve your code as per the suggestions given and try to resolve the issues. if you get stuck, post what you have tried and again, I am sure you will get help.

What you will NOT get is 'the whole code' - why? Because, I don't have the full code or requirements for YOUR project.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900