Share via

import export xml

StewartBW 1,905 Reputation points
2024-04-07T16:42:27.6866667+00:00

Hello

Using Access database engine and OleDbDataReader I need to open a table, read all columns of a single row and save the data in xml, or import back to the database.

Using MyConnection As New OleDbConnection(dbstring)
MyConnection.Open()
Using ReadUsers As New OleDbCommand("SELECT * FROM tableName WHERE columnField = 'blah'", MyConnection)
Using MyReaders As OleDbDataReader = ReadUsers.ExecuteReader
MyReaders.Read()
Using MyWriter As New XmlTextWriter(SFD.FileName, Encoding.UTF8)
MyWriter.WriteStartDocument(True)
MyWriter.Formatting = Formatting.Indented
MyWriter.Indentation = 2
MyWriter.WriteStartElement(Field) / MyWriter.WriteString(Value) / MyWriter.WriteEndElement()

It works but when reading it back, XmlTextReader will not work as expected

Using MyReader As New XmlTextReader(OFD.FileName)
While MyReader.Read
MyReader.ReadStartElement(Field) / MyReader.ReadString() / MyReader.ReadEndElement()

I found that it's forward-only, so a waste of time, anyone can suggest which class to use in .net framework 4.0?

Developer technologies | VB
Developer technologies | C#
Developer technologies | C#

An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.

0 comments No comments

Answer accepted by question author

Jiachen Li-MSFT 34,241 Reputation points Microsoft External Staff
2024-04-08T10:22:20.67+00:00

Hi @StewartBW ,

You can consider using the DataSet class's ReadXml and WriteXml methods.

You can serialize the data from the database into XML using the WriteXml method of the DataSet class, and then deserialize it back into a DataSet using the ReadXml method.

Best Regards.

Jiachen Li


If the answer is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

Was this answer helpful?

1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.