24 June 2015


Artikel ini lanjutan dari Part 1

Kode selengkapnya:
Option Explicit
Dim oConn As New ADODB.Connection

Dim rsData As New ADODB.Recordset
Dim strConn As StringDim SQL As String

Private Sub Form_Load()
strConn = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
          "Data Source=" & App.Path & "\latihan.mdb;" & _
          "Persist Security Info=False"
ListTables
End Sub

Sub Open_Connection()
Set oConn = New ADODB.Connection
oConn.ConnectionString = strConn
oConn.Open
End Sub

Sub ListTables()
Open_Connection
Dim rs As ADODB.Recordset

List1.Clear
Set rs = oConn.OpenSchema(adSchemaTables, _
         Array(Empty, Empty, Empty, "Table"))
Do While Not rs.EOF
    List1.AddItem rs!TABLE_NAME
    rs.MoveNext
Loop

rs.Close
oConn.Close

List1.ListIndex = 0
End Sub

Sub
Load_Data(TableName As String)
Open_Connection
Set rsData = New ADODB.Recordset
SQL = "SELECT * FROM " & TableName
With rsData
    .CursorLocation = adUseClient
    .Open SQL, oConn, adOpenDynamic, adLockOptimistic
    .ActiveConnection = Nothing
End With
Set
DataGrid1.DataSource = rsData
oConn.Close
End Sub

Private Sub List1_Click()
Load_Data List1.Text
End Sub


Runtime:



Click here if you like this article.


0 comments: