Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2009
    Posts
    1

    Unanswered: How to compare user's entry on GUI with the record in database?

    My ACCESS database has table Staff with attributes StaffID, StaffName, Password and Role.

    my GUI shows User in a combo dropdownlist. I manage to to load this part.

    Code:
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
            Dim conn As New OleDbConnection(connString)
            Try
                Dim comm_Staff As New OleDbCommand("Select * from Staff", conn)
                conn.Open()
                Dim da_staff As New OleDbDataAdapter(comm_Staff)
                Dim ds As New DataSet
                da_staff.Fill(ds, "Staff")
                cbxStaff.DataSource = ds.Tables("Staff")
                cbxStaff.DisplayMember = "StaffName"
            Catch ex As Exception
                MessageBox.Show(ex.Message)
            End Try
        End Sub
    Next there's a textbox for user to enter password.
    If the password entered is match with the one in the database, proceed. Else, msgbox("Wrong password!")
    I don't know how to do this part. Please help!! Very helpless!

    Code:
    Private Sub btnLogIn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogIn.Click
    
            If Not (tbxPassword.Text.Length = 4) Then
                MsgBox("Password is four character long.", MsgBoxStyle.Exclamation, "Password error")
                tbxPassword.Text = Nothing
            End If
    
            Dim conn As New OleDbConnection(connString)
            Try
    
            'if tbxPassword.text = password of the selected StaffID
            'Form2.Show()
            'else
            'MsgBox("wrong password")
    
    
            Dim commGetPW As New OleDbCommand("SELECT password FROM staff where staffname = @userid", conn)
            commGetPW.Parameters.AddWithValue("@userid", cbxStaff.SelectedValue.ToString)
            conn.Open()
            Dim reader As OleDbDataReader = commGetPW.ExecuteReader
            Dim chkPW As String
            If reader.Read Then
                chkPW = Convert.ToString(reader("Password"))
            Else
                MsgBox("i m not reading")
            End If
            reader.Close()
    
            Catch ex As Exception
            MessageBox.Show(ex.Message)
            End Try
    
        End Sub

  2. #2
    Join Date
    Feb 2009
    Posts
    23
    since you have already done loading its user in a combobox, why dont you load the staff id and its corresponding password in listbox/combobox with (2 colums)(set its visibility into false) then if user click or choose user id on your combobox that it will find its matching text in another combobox or listbox. See MSForm2.ocx or .dll not sure. it automatically find its matching text in its list.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •