You are on page 1of 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