import export xml

StewartBW 585 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?

C#
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.
10,458 questions
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,620 questions
0 comments No comments
{count} votes

Accepted answer
  1. Jiachen Li-MSFT 27,501 Reputation points Microsoft Vendor
    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful