Im using Microsoft Visual Studio 2012 and Microsoft Access
What code/sql will I add to check whether User is an admin or a regular user? so it can load to a Admin form or Regular user form.
My professor told me to use a FieldName "LoginType" in my database.. but i don't know how to use it.

Here's my Form code:

Private Sub btnSign_Click(sender As Object, e As EventArgs) Handles btnSign.Click
        Dim Username As String
        Dim Password As String

        Username = txtID.Text
        Password = txtPassword.Text

        If Me.TblUserTableAdapter.ScalarQueryLogin(Username, Password) Then
            MessageBox.Show("Welcome you are successfully logged in")
            MessageBox.Show("Invalid Username or Password Please Try Again")
            txtID.Text = String.Empty
            txtPassword.Text = String.Empty
        End If
    End Sub


FROM            TblUser
WHERE        (ID = ?) AND (LASTNAME = ?)

Please help This is for my thesis.

Recommended Answers

All 6 Replies

you can identify the admin from Login name, or login ID, and password.
1st make the admin login ID and password:

Let it be like:
Login ID: adminlogin
Login pass: admin pass

if this match then he is the admin else not then it is free user...

Thanks btw can you review this code

   For i = 0 To ds.Tables(0).Rows.Count - 1

                If ds.Tables(0).Rows(i).Item(0) = txtID.Text Then
                    MessageBox.Show("UserName Matched")

                    If ds.Tables(0).Rows(i).Item(1) = txtPassword.Text Then
                        MessageBox.Show("Password Matched")

                        MessageBox.Show("Invalid Password!")
                        MessageBox.Show(attempt & " out of 3")
                        attempt = attempt + 1
                    End If
                    MessageBox.Show("Invalid Username")

                End If

The message box "Invalid Username" is appearing first then "Username Matched" then "Password Matched"

1st you need to set the user level, i can see your query LOGINTYPE maybe this is for user Level, you can try this code

        Dim conn As SqlClient.SqlConnection
        Dim cmdlogin As New SqlClient.SqlCommand
        Dim dalogin As New SqlClient.SqlDataAdapter
        Dim dslogin As New DataSet
        Dim dtlogin As New DataTable

        If txtUsername.Text = "" Or txtPassword.Text = "" Then
            MsgBox("Please fill in the Blank", MsgBoxStyle.OkOnly)
                conn = GetConnect()
                cmdlogin = conn.CreateCommand
                cmdlogin.CommandText = "SELECT ID, PASSWORD, LOGINTYPE FROM TblUser WHERE (ID = '" & txtUsername.Text & "')  And (PASSWORD = '" & txtPassword.Text & "')"
                dalogin.SelectCommand = cmdlogin
                dalogin.Fill(dslogin, "TblUser")
                dtlogin = dslogin.Tables("TblUser")
                If (dtlogin.Rows.Count > 0) Then
                    if dtlogin.rows(0).item(2) = "Admin" then
                    end if
                MsgBox("Wrong Password")
                end if

if you have any problem, please ask me or if i fix your problem, please vote me. Thank You!

it says Error 1 'GetConnect' is not declared. It may be inaccessible due to its protection level

Try this

  Dim conn As New SqlClient.SqlConnection ("Your db provider, data source and password")
  Dim cmdlogin As New SqlClient.SqlCommand("SELECT ID, PASSWORD, LOGINTYPE FROM TblUser WHERE ID = '" & txtUsername.Text & "' And PASSWORD = '" & txtPassword.Text & "'", conn)
  Dim dr As SQLDataReader = cmd.ExecuteReader

  If = False Then
    If = dr("Admin") Then
    End If      
  End If

you need to create a module, and fill it with this code,

    Public conn As SqlClient.SqlConnection
    Public Function GetConnect()
        conn = New SqlClient.SqlConnection("Data Source=SERVERNAME;Initial Catalog=DATABASENAME;Integrated Security=True")
        Return conn
    End Function
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.