Office中国论坛/Access中国论坛
标题:
XML与ADODB.Recordset
[打印本页]
作者:
fan0217
时间:
2008-8-31 16:08
标题:
XML与ADODB.Recordset
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,也可以替代临时表使用。
作者:
tmtony
时间:
2008-8-31 22:40
这个是否也要引用xml
作者:
fan0217
时间:
2008-9-1 09:06
原帖由
tmtony
于 2008-8-31 22:40 发表
这个是否也要引用xml
对,也需要引用xml
欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/)
Powered by Discuz! X3.3