hello i am new to the coding world and i am trying to get this login code to only accept the names and passwords in the access database, current any can login. please assist

Imports System.Data
Imports System.Data.OleDb
Imports System.Data.DataTable
Public Class Form1

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click
    Dim conn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Katlego\Documents\logindb.accdb")
    Dim cmd As New OleDbCommand("select * from logintable where user1=@user1 and pass1=@pass1", conn)
    cmd.Parameters.Add("@user1", OleDbType.VarChar).Value = txtUsername.Text
    cmd.Parameters.Add("@user1", OleDbType.VarChar).Value = txtPassword.Text
    Dim adapter1 As New OleDbDataAdapter(cmd)
    Dim logintable As New DataTable
    If logintable.Rows.Count <=
        0 Then
        MsgBox("error username or password")
        MsgBox("login successfull")
    End If
End Sub

Private Sub btnCancel_Click(sender As Object, e As EventArgs) Handles btnCancel.Click
End Sub

End Class

Recommended Answers

All 2 Replies

On line 5 change @user1 to @pass1

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.