0% found this document useful (0 votes)
40 views2 pages

Learn How To Log in The User by Checking The Username and Password Stored in An Access Database

This document describes how to log users into an application by checking their username and password stored in an Access database. It involves creating a database table called "users" with fields for ID, username, password, first name, and last name. Code is provided to connect the application to the database, execute a query to check the username and password, and display a welcome message or error based on whether the user is found.

Uploaded by

Erick Castillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views2 pages

Learn How To Log in The User by Checking The Username and Password Stored in An Access Database

This document describes how to log users into an application by checking their username and password stored in an Access database. It involves creating a database table called "users" with fields for ID, username, password, first name, and last name. Code is provided to connect the application to the database, execute a query to check the username and password, and display a welcome message or error based on whether the user is found.

Uploaded by

Erick Castillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Learn how to log in the user by checking the username and password stored in an Access

database.

First create a table in Access database and call it users.

There are four fields in the users table:

ID, username, password, FirstName, LastName

Then add a sample record like I did in the following:

Now let's connect the program in Simple Login Tutorial to the database we created.

Add the following code above Public Class Form1


Imports System.Data.OleDb

Then add the following declarations below Public Class Form1


Dim provider As String
Dim dataFile As String
Dim connString As String
Dim myConnection As OleDbConnection = New OleDbConnection
The following code is the Button1 click event:
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
provider = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source ="
'Change the following to your access database location
dataFile = "C:\Users\Jimmy\Documents\customers.accdb"
connString = provider & dataFile
myConnection.ConnectionString = connString

'the query:
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM [users] WHERE [username] = '" &
TextBox1.Text & "' AND [password] = '" & TextBox2.Text & "'", myConnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader
' the following variable is hold true if user is found, and false if user is not found
Dim userFound As Boolean = False
' the following variables will hold the user first and last name if found.
Dim FirstName As String = ""
Dim LastName As String = ""

'if found:
While dr.Read
userFound = True
FirstName = dr("FirstName").ToString
LastName = dr("LastName").ToString
End While

'checking the result


If userFound = True Then
Form2.Show()
Form2.Label1.Text = "Welcome " & FirstName & " " & LastName
Else
MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid Login")
End If
End Sub

You might also like