您现在的位置: > 技术沙龙 > WEB开发 > XML > 将Recordset作为XML保存
  • 相关软件
    >将Recordset作为XML保存 创建者:webmaster 更新时间:2005-07-02 00:37

    微软使得将ActiveX数据对象(ADO)的Recordset作为XML在ADO 2.1里保存成为可能。这对于将Recordset保存在客户计算机上用于脱机使用很有用处。如果你希望通过可扩展样式表语言转换(XSLT)来操控Recordset的数据,那么这一能力也是很有用的。


    要将Recordset作为XML来保存,就要调用Save方法,并将目标文件及adPersistXML标志进行传递:


    Dim rst As Recordset

    Set rst = New Recordset
    rst.ActiveConnection = "PROVIDER=SQLOLEDB;DATA SOURCE=SQLServer;" & _
                           "Initial Catalog=pubs;Integrated Security=SSPI"
    rst.CursorLocation = adUseClient
    rst.Open "Select * from authors where au_lname = 'Smith'"
    rst.SaveApp.Path & "\recordset.xml", adPersistXML
    rst.Close


    如果所指定的文件命已经存在,那么对Save方法的调用就会导致一个运行错误。


    要打开已经保存的Recordset,就要将文件名传递给Recordset的Open方法。设置ActiveConnection属性能够让你将Recordset保存会数据库里:


    Dim rst As Recordset

    Set rst = New Recordset
    rst.CursorLocation = adUseClient
    rst.OpenApp.Path & "\recordset.xml"
    rst.ActiveConnection = "PROVIDER=SQLOLEDB;DATA SOURCE=SQLServer;" & _
                           "Initial Catalog=pubs;Integrated Security=SSPI"

    MsgBoxrst.RecordCount


    相关文章
    本页查看次数: