Dear Vb Lover,

Saya lg latihan ekspor impor data, klo ekspor nda masalah tapi
impornya nda bisa. Mohon bantuannya yach...

################################################################
Option Explicit

Dim con As ADODB.Connection
Dim rs As ADODB.Recordset

Public Function ImporData(sFileXML As String) As Recordset
On Error GoTo ImporErr
    Dim adost As New ADODB.Stream
    Set adost = New ADODB.Stream
    Dim adors As New ADODB.Recordset
    Set adors = New ADODB.Recordset
    adost.Open
    adost.LoadFromFile sFileXML
    adost.Position = 0
    adors.Open adost
    Set ImporData = adors
    adost.Close
    Set adost = Nothing
    Set adors = Nothing
    MsgBox ("Impor Sukses")
    Exit Function
ImporErr:
    MsgBox ("Ga bisa impor")
End Function

Private Sub Command1_Click()
    Call KonekTabel
    If MsgBox("Apakah anda yakin ?", vbInformation + vbYesNo,
"Perhatian") = vbYes Then
        rs.UpdateBatch
    Else
        rs.CancelBatch
    End If
    Call SetOffline
End Sub

Private Sub Command3_Click()
On Error GoTo TampilErr
    Call KonekTabel
    rs.MoveFirst
    rs.Find "user='" & txtnama.Text & "'"
    Call SetOffline
TampilErr:
    MsgBox ("Data ga ada")
    Exit Sub
End Sub

Private Sub Command4_Click()
    Call EksporKeXML(rs)
End Sub

Private Sub Command5_Click()
Dim sFileXML As String
    Call ImporData(sFileXML)
End Sub

Private Sub Form_Load()
    Set con = New ADODB.Connection
    Set rs = New ADODB.Recordset
    con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=C:\Documents and
Settings\Administrator\Desktop\tes\billing.mdb;Persist Security
Info=False"
    con.Open
    rs.CursorLocation = adUseClient
    rs.Open "transaksi", con, adOpenStatic, adLockBatchOptimistic
    Set Me.DataGrid1.DataSource = rs
    Call SetOffline
End Sub

Private Sub EksporKeXML(rs As Recordset)
On Error GoTo EksporErr
    Dim adost As ADODB.Stream
    Set adost = New ADODB.Stream
    rs.Save adost, adPersistXML
    adost.SaveToFile App.Path & "\" & rs.Source & _
    ".xml", adSaveCreateOverWrite
    MsgBox ("Data Telah di ekspor ke XML")
    adost.Close
    Set adost = Nothing
    Exit Sub
EksporErr:
    MsgBox ("ga bisa Ekspor Data")
End Sub

Private Sub KonekTabel()
    con.Open
    Set rs.ActiveConnection = con
End Sub

Private Sub SetOffline()
    Set rs.ActiveConnection = Nothing
    If con.State = adStateOpen Then con.Close
End Sub
#################################################################


Kirim email ke