我需要根据数据库里的内容生成XML文件,语句是
Adodc1.Recordset.Save "D:\recordset.xml", adPersistXML
但是老是有下面的错误:
run-time error '91':
Object variable or with block variable not set.在我写上面的语句时,在persistformat提示列表中也没有adPersistXML,只有adPersistADTG一项,我已经引用了MSXML3.0了,是不是还需要引用一些library?请指点迷津

解决方案 »

  1.   

    可能ado引用的版本低(如2。0)
      

  2.   

    不需要引用msxml对象,直接用:'例子:
    Sub sql1()
        Dim iRe As ADODB.Recordset
        Dim iConc As String
        
        iConc = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
            "User ID=sa;Password=;Initial Catalog=acc_演示数据7;Data Source=ymn"
        Set iRe = New ADODB.Recordset
        iRe.Open "凭证库", iConc, adOpenKeyset, adLockOptimistic
    End Sub
      

  3.   

    问题应该与你的记录集打开方式有关.我上面的测试过,正常.注意根据你的情况修改iconc中的用户名,密码,数据库名,服务器名
    iConc = "Provider=SQLOLEDB.1;Persist Security Info=True;" & _
            "User ID=用户名;Password=密码;Initial Catalog=数据库名;Data Source=SQL服务器名"
      

  4.   

    Dim conDB As New ADODB.ConnectionPrivate Sub cmdGetData_Click()
        Dim rsInventory As New ADODB.Recordset
        Dim stmInventory As New ADODB.Stream
        conDB.ConnectionString = ("Provider=SQLOLEDB.1;Server=Pinatubo;User ID=training; PWD=password;Initial Catalog=XMLTraining;")
        conDB.Open
        rsInventory.Open "tblInventory", conDB, adOpenDynamic, adLockOptimistic
        rsInventory.Save stmInventory, adPersistXML
        stmInventory.SaveToFile App.Path & "\inventory.xml", adSaveCreateOverWrite
        wbXML.Navigate App.Path & "\inventory.xml"
        conDB.Close
    End Sub
      

  5.   

    Adodc1.Recordset.Save "D:\recordset.xml", adPersistXML
    你用的是ado控件,建议使用ado对象
      

  6.   

    这样是可以保存为xml文件,但是这样保存的xml文件,内容很奇怪,不如在查询分析器中得到的结果明显,不知道怎么样可以做到保存的文件的内容和查询分析器中得到的结构一样呢?