Option Explicit On
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Dim objCon As OleDbConnection
Dim strSQL As String
Dim strConnection As String = "Provider= Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\User\Desktop\Visual Basic Program\Salesomting_service\ฐานข้อมูล1.accdb"
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim attempt As Integer = 0
Private Sub BtnLoginL_Click(sender As System.Object, e As System.EventArgs) Handles BtnLoginL.Click
Dim warning As String = "คุณกรอกข้อมูลไม่ถูกต้อง" & vbNewLine & vbNewLine + _
"If attempt var = 3" + vbNewLine + _
"System will shutdown."
If (TbnUsername.Text = "") And (TbnPassword.Text = "") Then
attempt = attempt + 1
MsgBox("กรุณากรอกข้อมูลให้ครบครับ" & vbNewLine & vbNewLine + _
warning, MsgBoxStyle.Exclamation, "Sorry sir!!" + _
"Now attempt var " & attempt)
ElseIf (TbnUsername.Text = "") Then
attempt = attempt + 1
MsgBox("กรุณาใส่ Username" & vbNewLine & vbNewLine + _
warning, MsgBoxStyle.Information, "Sorry sir!!" + _
"Now attempt var " & attempt)
ElseIf (TbnPassword.Text = "") Then
attempt = attempt + 1
MsgBox("กรุณาใส่ Password" & vbNewLine & vbNewLine + _
warning, MsgBoxStyle.Exclamation, "Sorry sir!!" + _
"Now attempt var " & attempt)
Else
Dim strName = TbnUsername.Text
Dim strPass = TbnPassword.Text
With objCon
.Close()
If (.State = ConnectionState.Closed) Then
.ConnectionString = strConnection
.Open()
MsgBox("ConnectionState.Open", MsgBoxStyle.Information, "Connected")
End If
End With
ds.Clear()
strSQL = "Select * from Login Where Login_Name ='" & TbnUsername.Text & "' And Login_Password='" & TbnPassword.Text & "'"
da = New OleDbDataAdapter(strSQL, objCon)
da.Fill(ds, "Login")
If (ds.Tables("Login").Rows.Count <> 0) Then
MaximizeBox = True
MinimizeBox = True
MsgBox("Hello! :" + strName + vbNewLine + _
"Login สำเร็จ", MsgBoxStyle.OkOnly, "Welcome" + strName)
Else
MaximizeBox = False
MinimizeBox = False
attempt = attempt + 1
MsgBox("OOP!")
End If
End If
If (attempt = 3) Then
MsgBox("Windows is shutting down...", MsgBoxStyle.Critical, "Goodbye")
Close()
End If
End Sub
End Class
Dim objcon As new OleDbConnection("Provider= Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\User\Desktop\Visual Basic Program\Salesomting_service\ฐานข้อมูล1.accdb")
Option Explicit On
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
' Dim objCon As OleDbConnection
Dim strSQL As String
Dim strConnection As String = "Provider= Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\User\Desktop\Visual Basic Program\Salesomting_service\ฐานข้อมูล1.accdb"
Dim objcon As New OleDbConnection("Provider= Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\User\Desktop\Visual Basic Program\Salesomting_service\ฐานข้อมูล1.accdb")
Dim da As New OleDb.OleDbDataAdapter
Dim ds As New DataSet
Dim attempt As Integer = 0
Private Sub BtnLoginL_Click(sender As System.Object, e As System.EventArgs) Handles BtnLoginL.Click
Dim warning As String = "คุณกรอกข้อมูลไม่ถูกต้อง" & vbNewLine & vbNewLine + _
"If attempt var = 3" + vbNewLine + _
"System will shutdown."
If (TbnUsername.Text = "") And (TbnPassword.Text = "") Then
attempt = attempt + 1
MsgBox("กรุณากรอกข้อมูลให้ครบครับ" & vbNewLine & vbNewLine + _
warning, MsgBoxStyle.Exclamation, "Sorry sir!!" + _
"Now attempt var " & attempt)
ElseIf (TbnUsername.Text = "") Then
attempt = attempt + 1
MsgBox("กรุณาใส่ Username" & vbNewLine & vbNewLine + _
warning, MsgBoxStyle.Information, "Sorry sir!!" + _
"Now attempt var " & attempt)
ElseIf (TbnPassword.Text = "") Then
attempt = attempt + 1
MsgBox("กรุณาใส่ Password" & vbNewLine & vbNewLine + _
warning, MsgBoxStyle.Exclamation, "Sorry sir!!" + _
"Now attempt var " & attempt)
Else
Dim strName = TbnUsername.Text
Dim strPass = TbnPassword.Text
With objCon
.Close()
If (.State = ConnectionState.Closed) Then
.ConnectionString = strConnection
.Open()
MsgBox("ConnectionState.Open", MsgBoxStyle.Information, "Connected")
End If
End With
ds.Clear()
strSQL = "Select * from Login Where Login_Name ='" & TbnUsername.Text & "' And Login_Password='" & TbnPassword.Text & "'"
da = New OleDbDataAdapter(strSQL, objCon)
da.Fill(ds, "Login")
If (ds.Tables("Login").Rows.Count <> 0) Then
MaximizeBox = True
MinimizeBox = True
MsgBox("Hello! :" + strName + vbNewLine + _
"Login สำเร็จ", MsgBoxStyle.OkOnly, "Welcome" + strName)
Else
MaximizeBox = False
MinimizeBox = False
attempt = attempt + 1
MsgBox("OOP!")
End If
End If
If (attempt = 3) Then
MsgBox("Windows is shutting down...", MsgBoxStyle.Critical, "Goodbye")
Close()
End If
End Sub
End Class