Convert MS Access data to XML programmatically

  • Thread starter Thread starter Thu
  • Start date Start date
T

Thu

I store me reporting data in MS Access table, and I need
to programmatically generate XML file (in text) that
loads these data, include all these data with appropriate
definition, i.e. root, elements, entities, and sends
these data to another party on daily basis.

Does anyone know the easiest way to achieve this? Is
there a class that loads data from MS Access, match them
with definition files, and generate XML text file
automatically?

Thanks.
 
Hi,

Load the data in a dataset. Use the dataset.writexml method to save
it as xml.
Dim da As OleDbDataAdapter

Dim conn As OleDbConnection

Dim ds As New DataSet

conn = New OleDbConnection("Provider = Microsoft.JET.OleDB.4.0; Data Source
= USCG.mdb")

da = New OleDbDataAdapter("Select * from Rules", conn)

da.Fill(ds)

ds.WriteXml("C:\Rules.xml")

Ken
 
you need to use the oledbconnection, dataadapter and generate a dataset from
them. Us the writexml method of the dataset to write the data to the
currently set iostream

HTH

Private Sub WriteXmlToFile(thisDataSet As DataSet)
If thisDataSet Is Nothing Then
Return
End If
' Create a file name to write to.
Dim filename As String = "myXmlDoc.xml"
' Create the FileStream to write with.
Dim myFileStream As New System.IO.FileStream _
(filename, System.IO.FileMode.Create)
' Create an XmlTextWriter with the fileStream.
Dim myXmlWriter As New System.Xml.XmlTextWriter _
(myFileStream, System.Text.Encoding.Unicode)
' Write to the file with the WriteXml method.
thisDataSet.WriteXml(myXmlWriter)
myXmlWriter.Close()
End Sub


--
Regards - One Handed Man

Author : Fish .NET & Keep .NET
=========================================
This posting is provided "AS IS" with no warranties,
and confers no rights.
 
Back
Top