Imports System.Data
Imports System.Data.SqlClient
Public Class Login
Dim Conn As SqlConnection = New SqlConnection
Dim da As SqlDataAdapter
Dim sale As SqlCommand
Dim dssale As DataSet
Dim sqlserch As String
Dim serch_value As String
Dim ds As New DataSet
Dim IsFind As Boolean = False
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Dim sqlusers As String = ""
sqlusers = "select * from users where LOGINNAME = '" & txtname.Text & "'"
sqlusers &= "AND PASSWD = '" & txtpass.Text & "'"
With Conn
If .State = ConnectionState.Open Then .Close()
.ConnectionString = strConnString
.Open()
If IsFind = True Then
ds.Tables("users").Clear()
End If
da = New SqlDataAdapter(sqlusers, Conn)
da.Fill(ds, "users")
ds.Tables("users").Clear()
da = New SqlDataAdapter(sqlusers, Conn)
da.Fill(ds, "users")
If ds.Tables("users").Rows.Count > 0 Then
txtname.DataBindings.Clear()
txtpass.DataBindings.Add("text", ds, "users.PASSWD")
If txtpass.Text = txtpass.Text Then
Me.Hide()
Main.Show()
Else
MsgBox("รหัสผ่านไม่ถูกต้อง", , "ข้อผิดพลาด")
txtname.Text = ""
txtpass.Text = ""
txtname.Focus()
End If
Else
MsgBox("ไม่พบข้อมูลที่ต้องการเข้าระบบ", MsgBoxStyle.OkOnly, "ข้อผิดพลาด")
txtname.Text = ""
txtpass.Text = ""
txtname.Focus()
End If
End With
End Sub
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
If MessageBox.Show("ต้องการออกจากโปรแกรมใช่หรือไม่?", "คำยืนยัน", _
MessageBoxButtons.YesNo, MessageBoxIcon.Question) = vbYes Then
End
End If
End Sub
End Class