注册 登录
Office中国论坛/Access中国论坛 返回首页

的个人空间 http://www.office-cn.net/?0 [收藏] [复制] [分享] [RSS]

日志

XML与ADODB.Recordset

已有 2067 次阅读2008-9-22 06:45 |个人分类: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("帐目编号")
            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,也可以替代临时表使用。

评论 (0 个评论)

facelist doodle 涂鸦板

您需要登录后才可以评论 登录 | 注册

QQ|站长邮箱|小黑屋|手机版|Office中国/Access中国 ( 粤ICP备10043721号-1 )  

GMT+8, 2024-11-29 01:57 , Processed in 0.057913 second(s), 14 queries .

Powered by Discuz! X3.3

© 2001-2017 Comsenz Inc.

返回顶部