注冊(cè) 登錄
Office中國(guó)論壇/Access中國(guó)論壇 返回首頁(yè)

的個(gè)人空間 http://ctxi.cn/?0 [收藏] [復(fù)制] [分享] [RSS]

日志

XML與ADODB.Recordset

已有 2059 次閱讀2008-9-22 06:45 |個(gè)人分類:Access

CODE:

Public Function ReadXml(xmlFile As String) As ADODB.Recordset
    Dim rs As New ADODB.Recordset
        rs.Open xmlFile, "Provider=MSPersist", , , adCmdFile
    Set ReadXml = rs
    Set rs = Nothing
End Function
Public Sub SaveXml(sql As String, xmlFile As String)
    Dim conn As New ADODB.Connection
    Dim rs As New ADODB.Recordset
    Set conn = CurrentProject.Connection
        rs.Open sql, conn, adOpenKeyset, adLockReadOnly
        rs.Save xmlFile, adPersistXML
    Set rs = Nothing
    Set conn = Nothing
End Sub
Private Sub DelFile(xmlFile As String)
    Dim fso
        Set fso = CreateObject("Scripting.FileSystemObject")
        If fso.FileExists(xmlFile) Then
            fso.DeleteFile xmlFile
        End If
    Set fso = Nothing
End Sub
Sub ReadXmlTest()
    Dim strXmlFile As String
    Dim rs As New ADODB.Recordset
   
        strXmlFile = "C:\Test.xml"
        Set rs = ReadXml(strXmlFile)
        
        Do While Not rs.EOF
            Debug.Print rs("帳目編號(hào)")
            rs.MoveNext
        Loop
End Sub
Sub SaveXmlTest()
    Dim strXmlFile As String, strSQL As String
        strSQL = "SELECT * FROM 帳目;"
        strXmlFile = "C:\Test.xml"
        DelFile strXmlFile
        SaveXml strSQL, strXmlFile
End Sub
用這樣的方法,我們可以持久保存ADODB.Recordset,也可以替代臨時(shí)表使用。

評(píng)論 (0 個(gè)評(píng)論)

facelist doodle 涂鴉板

您需要登錄后才可以評(píng)論 登錄 | 注冊(cè)

QQ|站長(zhǎng)郵箱|小黑屋|手機(jī)版|Office中國(guó)/Access中國(guó) ( 粵ICP備10043721號(hào)-1 )  

GMT+8, 2024-10-23 10:20 , Processed in 0.058636 second(s), 14 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回頂部