Imports System.Data
Imports System.Data.SqlServerCe
Imports System.Data.SqlTypes
Imports System.Windows.Forms
Public Class Login
Public strconnstring As String = "Data source=D:\Copy of Project New\WindowsApplication1\WindowsApplication1\Database1.sdf;"
Public myCommand As SqlCeCommand
Public myconnection As SqlCeConnection
Public cmdstring As String
Private Sub Login_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
myconnection = New SqlCeConnection(strconnstring)
myconnection.Open()
Try
Dim cmdstring As String = "Select * From MyTable"
myCommand = New SqlCeCommand(cmdstring, myconnection)
myCommand.CommandType = CommandType.Text
Dim myDataReader As SqlCeDataReader = myCommand.ExecuteReader()
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub OK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles OK.Click
Try
cmdstring = "Select password FROM [myTable] where ID=" & txtid.Text
myCommand = New SqlCeCommand(cmdstring, myconnection)
myCommand.CommandType = CommandType.Text
Dim myDataReader As SqlCeDataReader = myCommand.ExecuteReader()
Dim strPassword As String
If myDataReader.HasRows Then
myDataReader.Read()
If IsDBNull(myDataReader("password")) Then
strPassword = ""
Else
strPassword = Trim(myDataReader("password"))
End If
If strPassword <> Trim(txtpass.Text) Then
MsgBox("Password mismatch")
Else
MsgBox("ล็อคอินเรียบร้อย")
Me.Hide()
Computer.Show()
End If
Else
MsgBox("ไม่มีข้อมูลในระบบ")
End If
Catch ex As Exception
MsgBox("กรุณาพิมพ์ข้อมูล")
End Try
End Sub