Imports System.Data
Imports System.Data.OleDb
Public Class Form1
Friend cn As OleDbConnection = New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=X:\DATA\Database4.accdb; Persist Security Info=False;")
Friend cmd As New OleDbCommand
Friend DA As New OleDbDataAdapter
Friend DS As New DataSet
Friend DR As OleDbDataReader
Friend oledb As String = ""
Friend Sub connect()
If cn.State = ConnectionState.Closed Then cn.Open()
End Sub
Friend Function cmd_excuteScalar()
connect()
cmd = New OleDbCommand(oledb, cn)
Return cmd.ExecuteScalar()
End Function
Friend Function cmd_excuteToDataTable()
connect()
DA = New OleDbDataAdapter(oledb, cn)
DS = New DataSet
DA.Fill(DS, "table")
Return DS.Tables("table")
End Function
Private Sub btn_login_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn_login.Click
connect()
oledb = "select count(*) from Member where Username='" & txt_username.Text & "' and Password='" & txt_password.Text & "'"
Dim user_count As Integer = cmd_excuteScalar()
If user_count <= 0 Then
MsgBox("Login Fail")
Else
MsgBox("login ok")
Me.Hide()
main.Show()
End If
oledb = "select * from Member where Username='" & txt_username.Text & "' and Password='" & txt_password.Text & "'"
Dim dts As DataTable = cmd_excuteToDataTable()
With main
.lbl_username.Text = dts.Rows(0)("username")
.lbl_name.Text = dts.Rows(0)("name")
.lbl_date.Text = Date.Now
End With
End Sub
End Class