Imports System.Data
Imports System.Data.OleDb
Public Class Form1
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.ACE.OLEDB.12.0;Data Source=D:\ปวส\2\โปรเจ็ค\ระบบจัดการฐานข้อมูลรับ-ส่งหนังสือ\WindowsApplication1\WindowsApplication1\bin\database\login.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 & "'"
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
Form1.Show()
usertxt.Text = ""
passtxt.Text = ""
Me.Hide()
Else
MessageBox.Show("กรุณาใส่ข้อมูลให้ถูกต้อง", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End Sub
End Class
Tag : .NET, Ms Access, VBScript, Web (ASP.NET), VB.NET