Option Explicit On
Imports System.Text
Imports System.Data
Imports System.Data.SqlClient
Public Class LoginForm1
Dim con As SqlConnection
Dim com As SqlCommand
Dim dt As DataTable
Dim sb As StringBuilder
Dim dr As SqlDataReader
Dim tmpautoid As String
Private Sub conn()
Dim conn As String = connectDB.strconn
con = New SqlConnection
With con
If .State = ConnectionState.Open Then .Close()
.ConnectionString = conn
.Open()
End With
End Sub
Private Sub OK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles OK.Click
sb = New StringBuilder
sb.Append("Select * From Login where Username = @username, Password = @password")
Dim loginForm1 As String = sb.ToString
com = New SqlCommand
With com
.CommandText = loginForm1$
.CommandType = CommandType.Text
.Connection = con
dr = .ExecuteReader
If dr.HasRows Then
dr.Read()
variable.tmpUsername = dr.Item("Username")
MDIAdmin.Show()
'Me.Hide()
'dr.Close()
Else
MessageBox.Show("ไม่มีข้อมูลผู้ใช้ในระบบครับ", "ผลการทำงาน", MessageBoxButtons.OK, MessageBoxIcon.Warning)
End If
End With
txtuser.Text = ""
txtpass.Text = ""
txtuser.Focus()
End Sub
End Class