Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Private Sub cmdDoc_Click()
- Dim Cn As ADODB.Connection
- Dim Rs As ADODB.Recordset
- Dim strSQL As String
- Dim bHople As Boolean
- 'Khoi tao moi mot doi tuong Connection
- Set Cn = New ADODB.Connection
- Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = testAccess.MDB"
- Cn.Open
- 'Thuc thi cau lenh SQL de lay tat ca Ten va Matkhau co trong CSDL
- strSQL = "Select FirstName, LastName from FullName"
- Set Rs = New ADODB.Recordset
- Rs.Open strSQL, Cn, adOpenStatic, adLockOptimistic
- 'Kiem tra xem du lieu doc ra co hop le khong
- If (Rs.BOF = True) Then
- MsgBox "Khong doc duoc thong tin nguoi dung trong co so du lieu"
- Rs.Close
- Cn.Close
- Exit Sub
- End If
- Rs.MoveFirst
- bHople = False
- 'Lan luot Tim kiem xem username va password co ton tai trong CSDL khong
- Do While ((Not Rs.EOF) And (Not bHople = True))
- If (Rs![FirstName] = txtMot.Text And Rs![LastName] = txtHai.Text) Then
- bHople = True
- Else
- Rs.MoveNext
- End If
- Loop
- 'Dong ket noi voi CSDL
- Rs.Close
- Cn.Close
- If (bHople = True) Then
- MsgBox "Co Phan Tu Nay Trong Table"
- 'Unload Me
- Else
- MsgBox "Nhap sai roi"
- End If
- End Sub
- Private Sub cmdLoad_Click()
- LoadLai
- End Sub
- Private Sub cmdSua_Click()
- Dim Cn As ADODB.Connection
- Dim Rs As ADODB.Recordset
- Dim strSQL As String
- Dim bHople As Boolean
- 'Khoi tao moi mot doi tuong Connection
- Set Cn = New ADODB.Connection
- Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = testAccess.MDB"
- Cn.Open
- 'Thuc thi cau lenh SQL de lay tat ca Ten va Matkhau co trong CSDL
- 'strSQL = "INSERT INTO FullName(FirstName, LastName) VALUES ('" & txtMot.Text & "','" & txtHai.Text & "')"
- strSQL = "UPDATE FullName SET FirstName='" & txtMot.Text & "', LastName ='" & txtHai.Text & "' WHERE ID = " & txtIDsua.Text
- Set Rs = New ADODB.Recordset
- Rs.Open strSQL, Cn, adOpenStatic, adLockOptimistic
- Cn.Close
- LoadLai
- End Sub
- Private Sub cmdThem_Click()
- Dim Cn As ADODB.Connection
- Dim Rs As ADODB.Recordset
- Dim strSQL As String
- Dim bHople As Boolean
- 'Khoi tao moi mot doi tuong Connection
- Set Cn = New ADODB.Connection
- Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = testAccess.MDB"
- Cn.Open
- 'Thuc thi cau lenh SQL de lay tat ca Ten va Matkhau co trong CSDL
- strSQL = "INSERT INTO FullName(FirstName, LastName) VALUES ('" & txtMot.Text & "','" & txtHai.Text & "')"
- Set Rs = New ADODB.Recordset
- Rs.Open strSQL, Cn, adOpenStatic, adLockOptimistic
- Cn.Close
- LoadLai
- End Sub
- Private Sub LoadLai()
- Dim id As Integer
- id = 0
- With testMSFlexGrid
- .Rows = 1
- .Cols = 3
- .TextMatrix(0, 0) = "ID"
- .TextMatrix(0, 1) = "First Name"
- .TextMatrix(0, 2) = "Last Name"
- End With
- Dim Cn As ADODB.Connection
- Dim Rs As ADODB.Recordset
- Dim strSQL As String
- 'Khoi tao moi mot doi tuong Connection
- Set Cn = New ADODB.Connection
- Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = testAccess.MDB"
- Cn.Open
- 'Thuc thi cau lenh SQL de lay tat ca Ten va Matkhau co trong CSDL
- strSQL = "Select ID, FirstName, LastName from FullName"
- Set Rs = New ADODB.Recordset
- Rs.Open strSQL, Cn, adOpenStatic, adLockOptimistic
- 'Kiem tra xem du lieu doc ra co hop le khong
- If (Rs.BOF = True) Then
- MsgBox "Khong doc duoc thong tin nguoi dung trong co so du lieu"
- Rs.Close
- Cn.Close
- Exit Sub
- End If
- Rs.MoveFirst
- 'Lan luot Tim kiem xem username va password co ton tai trong CSDL khong
- Do While ((Not Rs.EOF))
- id = id + 1
- With testMSFlexGrid
- .Rows = .Rows + 1
- .TextMatrix(id, 0) = Rs![id]
- .TextMatrix(id, 1) = Rs![FirstName]
- .TextMatrix(id, 2) = Rs![LastName]
- End With
- Rs.MoveNext
- Loop
- 'Dong ket noi voi CSDL
- Rs.Close
- Cn.Close
- MsgBox "Da Load xong"
- End Sub
- Private Sub cmdXoa_Click()
- Dim Cn As ADODB.Connection
- Dim Rs As ADODB.Recordset
- Dim strSQL As String
- Dim bHople As Boolean
- 'Khoi tao moi mot doi tuong Connection
- Set Cn = New ADODB.Connection
- Cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source = testAccess.MDB"
- Cn.Open
- 'Thuc thi cau lenh SQL de lay tat ca Ten va Matkhau co trong CSDL
- 'strSQL = "INSERT INTO FullName(FirstName, LastName) VALUES ('" & txtMot.Text & "','" & txtHai.Text & "')"
- strSQL = "DELETE FROM FullName WHERE ID = " & txtIDsua.Text
- '" & txtIDsua.Text & "'"
- Set Rs = New ADODB.Recordset
- Rs.Open strSQL, Cn, adOpenStatic, adLockOptimistic
- Cn.Close
- LoadLai
- End Sub
Advertisement
Add Comment
Please, Sign In to add comment