How to export data in a able to an XML file on the hard disk.

Source: Internet
Author: User

(Domestic version)



After several days of continuous research on ADO. net, and found another good function... That is, how to use it (if there is no error, related functions are also available in ado !)Writwxml,WritexmlschemaExport the data and schema structure in the datatable to the XML file on the hard disk, or useReadxml,ReadxmlschemaLoad the data and schema structure in the XML file into the able object in the dataset.

In some cases, data may need to be stored on the hard disk... To prevent unexpected demands...

' Declare Variables

Dim CN As Sqlconnection

Dim Da As Sqldataadapter

Dim DS As Dataset


Try

' Columnized sqlconnection object and connection string

CN =   New Sqlconnection ( " Data Source = localhost; initial catalog = northwind; Integrated Security = true " )

CN. open ()


' Real-column DataSet object

DS =   New Dataset

' Materialized sqldataadapter

Da =   New Sqldataadapter ( " Select * from MERs " , CN)

' Load the data returned by SQL Server to the datatable

Da. Fill (DS)

' Bind dataset to the DataGrid Control

Datagrid1.datasource = DS

Catch Ex As Sqlexception

' Error message displayed here

Finally

CN. Close ()


End   Try

Try

' Export table structure to the XSD File

DS. writexmlschema ( " C: \ table-def.xsd " )

' Export the data in the datatable to an XML file

DS. writexml ( " C: \ table-data.xml " )

Catch Ex As Exception

' Error message displayed here

End   Try

Try

' Create a new DataSet object

DS =   New Dataset

' Load table structure into Dataset

DS. readxmlschema ( " C: \ table-def.xsd " )

' Load XML data into datatable

DS. readxml ( " C: \ table-data.xml " )

' Bind dataset to the DataGrid Control

Datagrid1.datasource = DS

Catch Ex As Exception

' Error message displayed here

End   Try

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.