You are on page 1of 1

Imports System.Data.

OleDb
Public Class Form1
Dim conn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Users\lenovo\Documents\login.mdb")
Dim dr As OleDbDataReader

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
Try
conn.Open()
Dim cmd As New OleDbCommand("SELECT * FROM Table1 WHERE USERNAME='" &
TextBox1.Text & "' AND PASSWORD='" & TextBox2.Text & "'", conn)
dr = cmd.ExecuteReader()

If dr.HasRows = True Then


MsgBox("LOGIN SUCCESS")
Form2.Show()
Me.Hide()

Else
MsgBox("Username or Password are invalid")
End If
Catch ex As Exception
MsgBox(ex.Message)
Finally
conn.Close()
dr.Close()
End Try
End Sub

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


System.EventArgs) Handles Button2.Click
Form3.Show()
Me.Hide()
End Sub
End Class

You might also like