Office中国论坛/Access中国论坛

标题: 请帮忙,我按照示例代码试验不成功,帮我测测 [打印本页]

作者: zxh    时间: 2006-4-29 19:12
标题: 请帮忙,我按照示例代码试验不成功,帮我测测
步骤1
用以下代码导出pubs.xml到c:\
Private Sub Command0_Click()
   Call Main
End Sub
Public Sub Main()
    On Error GoTo ErrorHandler

    'recordset and connection variables
    Dim rstAuthors As ADODB.Recordset
    Dim Cnxn As ADODB.Connection
    Dim strCnxn As String
    Dim strSQLAuthors As String
     
    ' Open connection
    Set Cnxn = New ADODB.Connection
    strCnxn = "rovider=sqloledb;Data Source=127.0.0.1;" & _
        "Initial Catalog=Pubs;Integrated Security=SSPI;user id=sa;password="
    Cnxn.Open strCnxn
   
    Set rstAuthors = New ADODB.Recordset
    strSQLAuthors = "SELECT au_id, au_lname, au_fname, city, phone FROM Authors"
    rstAuthors.Open strSQLAuthors, Cnxn, adOpenDynamic, adLockOptimistic, adCmdText
     
    'For sake of illustration, save the Recordset to a diskette in XML format
    rstAuthors.Save "c:\Pubs.xml", adPersistXML

    ' clean up
    rstAuthors.Close
    Cnxn.Close
    Set rstAuthors = Nothing
    Set Cnxn = Nothing
    Exit Sub
   
ErrorHandler:
    'clean up
    If Not rstAuthors Is Nothing Then
        If rstAuthors.State = adStateOpen Then rstAuthors.Close
    End If
    Set rstAuthors = Nothing
   
    If Not Cnxn Is Nothing Then
        If Cnxn.State = adStateOpen Then Cnxn.Close
    End If
    Set Cnxn = Nothing
   
    If Err <> 0 Then
        MsgBox Err.Source & "-->" & Err.Description, , "Error"
    End If
End Sub
'EndSaveVB

步骤2
请到http://www.microsoft.com/china/msdn/library/office/office/USodcac2003.mspx#EHD
找到“导入 XML 文件的结构和数据”那段示例代码,帮忙试一下,我试了,不能成功导入数据,只在当前Access2003里生成了三个表(AttributeType,data,ElementType且没有记录的)为什么?我要实现它能够成功的从pubs.xml里导入数据。




欢迎光临 Office中国论坛/Access中国论坛 (http://www.office-cn.net/) Powered by Discuz! X3.3