Imports System.Data
Imports System.Data.OleDb
Public Class LoginForm
Dim StrConn As String
Dim Conn As New OleDbConnection
Dim da As OleDbDataAdapter
Dim ds As New DataSet
Dim dt As DataTable
Dim dr As DataRow
Dim CurrentEmployees As Integer
Dim IsFind As Boolean = False
Dim btnChk As String
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 LoginForm_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
StrConn = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\ae\LibralyProject\libraly.accdb"
With Conn
If .State = ConnectionState.Open Then Close()
.ConnectionString = StrConn
.Open()
End With
End Sub
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Cnnstring = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=H:\ae\LibralyProject\libraly.accdb"
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
.Close()
End With
If txtUserName.Text = "" Or txtPwd.Text = "" Then
MessageBox.Show("ใส่ข้อมูล", "No UserID", MessageBoxButtons.OK, MessageBoxIcon.Error)
Else
ReadMyData(Cnnstring)
End If
End Sub
Public Sub ReadMyData(ByVal myConnString As String)
Dim str_idname As String = ""
Dim str_password As String = ""
On Error GoTo 0
With Cnn
If .State = ConnectionState.Open Then Close()
.ConnectionString = Cnnstring
.Open()
End With
SqlSelect = "select * from users Where userid = '" & txtUserName.Text & "' and userpassword = '" & txtPwd.Text & "'"
Dim OleCommand As New OleDbCommand(SqlSelect, Cnn)
OleReader = OleCommand.ExecuteReader
OleReader.Read()
If Not OleReader.HasRows Then
str_idname = OleReader.Item("userid")
str_password = OleReader.Item("userpassword")
Else
MessageBox.Show("User name or password Incorrec")
End If
Cnn.Close()
If txtUserName.Text = str_idname And txtPwd.Text = str_password Then
Form2.Show()
txtUserName.Text = ""
txtPwd.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
End Sub
End Class
ติดเออเร่อ ตรงบรรทัด OleReader = OleCommand.ExecuteReader
The table 'users' is already opened exclusively by another user, or it is already open through the user interface and cannot be manipulated programmatically.