Imports System.Data
Imports System.Data.OleDb
Public Class Form1
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
Dim conStr As String = "Provider=Microsoft.Ace.Oledb.12.0;Data Source=C:\Car\db\car.accdb;"
Dim conn As New OleDbConnection(conStr)
conn.Open()
Dim sql As String = "SELECT * FROM Admin"
Dim cmd As New OleDbCommand(sql, conn)
Dim reader As OleDbDataReader = cmd.ExecuteReader()
Dim TbUsername As String = TbxUsername.Text
Dim TbPassword As String = TbxPassword.Text
Dim _name() As String
Dim pass() As String
While (reader.Read())
_name(reader.HasRows) = reader("Username")
pass(reader.HasRows) = reader("Password")
End While
If (TbUsername <> "") Then
If (TbUsername = _name(reader.HasRows)) Then
If (TbPassword = pass(reader.HasRows)) Then
Dim home As New Form2()
home.Show()
Else
MsgBox("Username หรือ Password ผิดพลาด")
End If
Else
MsgBox("Username หรือ Password ผิดพลาด")
End If
Else
MsgBox("กรุณาใส่ Username และ Password")
End If
conn.Close()
End Sub
End Class