Imports System.Data
Imports System.Data.OleDb
Public Class LoginForm1
Dim Cnn As New OleDbConnection(Cnnstring)
Dim Cnnstring As String
Dim SqlSelect As String
Dim OleReader As OleDbDataReader
Dim UserIDA As String
Dim PassIDA As String
Private Sub cmdlogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdlogin.Click
Cnnstring = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=database/project1.accdb;"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
If usertxt.Text = "" Then
MessageBox.Show("ใส่ข้อมูล", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
ReadMyData(Cnnstring)
End If
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
On Error GoTo 0
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
End With
SqlSelect = "select * from tbuserlogin Where Username = '" & usertxt.Text & "' and Password = '" & passtxt.Text & "'"
Dim OleCommand As New OleDbCommand(SqlSelect, Cnn)
OleReader = OleCommand.ExecuteReader
OleReader.Read()
UserIDA = OleReader.Item("username")
PassIDA = OleReader.Item("password")
Cnn.Close()
If usertxt.Text = UserIDA And passtxt.Text = PassIDA Then
admin.Show()
usertxt.Text = ""
passtxt.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If?>