0% found this document useful (0 votes)
22 views

"Provider Microsoft - ACE.Oledb.12.0 Data Source " "C /Norhanna/Access/Database11.accdb"

This code connects to an Access database to authenticate login credentials. It opens a connection to the database using a connection string. A SELECT query searches the "tbl_login" table for a matching username and password from the text boxes. If a match is found, it retrieves the first and last name fields and displays them on Form2, hiding the current form. If no match is found, it shows an error message.

Uploaded by

horranda
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)
22 views

"Provider Microsoft - ACE.Oledb.12.0 Data Source " "C /Norhanna/Access/Database11.accdb"

This code connects to an Access database to authenticate login credentials. It opens a connection to the database using a connection string. A SELECT query searches the "tbl_login" table for a matching username and password from the text boxes. If a match is found, it retrieves the first and last name fields and displays them on Form2, hiding the current form. If no match is found, it shows an error message.

Uploaded by

horranda
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/ 1

Imports System.Data.

OleDb
Public Class Form1
Dim provider As String
Dim datafile As String
Dim connstring As String
Dim myconnection As OleDbConnection = New OleDbConnection

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles MyBase.Load

End Sub

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button1.Click
provider = "Provider=Microsoft.ACE.Oledb.12.0;Data Source="
datafile = "C;\Norhanna\Access\Database11.accdb"

connstring = provider & datafile


myconnection.ConnectionString = connstring

myconnection.Open()
'query
Dim cmd As OleDbCommand = New OleDbCommand("SELECT * FROM tbl_login
WHERE username='" & txtUsername.text & "' AND Password='" &
txtboxpassword.Text & "'", myconnection)
Dim dr As OleDbDataReader = cmd.ExecuteReader

'check if user is found


Dim userFound As Boolean = False
Dim FirstName As String = ""
Dim LastName As String = ""

'if user is found, display firstname and lastname on the next form
W hile dr.Read
userFound = True
FirstName = dr("FirstName").ToString
LastName = dr("LastName").ToString
End While

If userFound = True Then


Form2.Show()
Form2.Label2.Text = FirstName & " " & LastName
Me.Hide()
Else
MsgBox("Sorry,Username or Password not found",
MsgBoxStyle.OkOnly, "Invalid Login")
End If

End Sub

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As


System.EventArgs) Handles Button2.Click
txtboxpassword.Text = ""
Txtboxusername.Text = ""
End Sub
End Class

You might also like