Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Linq
Imports System.Text
Imports System.Windows.Forms
Imports System.Collections
Imports System.Data.SqlClient
Imports System.Data.OleDb
Imports System.IO
Public Class BS_Login
'Private Con As SqlConnection
'Private sql As String
'Private command As SqlCommand
Private Adapter As SqlDataAdapter
'Private data As DataSet
'Private BindingSrc As BindingSource
Private sb As StringBuilder
Private Conn As SqlConnection
Private com As SqlCommand
Private dr As SqlDataReader
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim strConn As String
strConn = "Provider=SQLOLEDB; " & _
"Data Source=PC2011110713SUS\SQL; " & _
"Initial Catalog=BookShop_DB; " & _
"UID=sa; " & _
"Password=1234;"
If (Conn.State = ConnectionState.Open) Then
Conn.Close()
End If
Conn.ConnectionString = strConn
Conn.Open()
sb.Append("select username,password from bs_em ")
sb.Append(" where username = '" + TextBox1.Text.Trim + "' ")
sb.Append(" and password = '" + TextBox2.Text.Trim + "' ")
Dim sqlLogin
sqlLogin = sb.ToString
com.CommandType = CommandType.Text
com.CommandText = sqlLogin
com.Connection = Conn
dr = com.ExecuteReader
If (dr.HasRows) Then
dr.Read()
Dim mian = New BS_Mian
Dim log = New BS_Login
mian.Show()
log.Hide()
Else
MessageBox.Show("คุณกรอก Username หรือ Password ไม่ถูกต้อง", "แจ้งเตือน", MessageBoxButtons.OK, MessageBoxIcon.Error)
cler()
TextBox1.Focus()
End If
End Sub
End Class