Link to home
Start Free TrialLog in
Avatar of Eric Burton
Eric BurtonFlag for United States of America

asked on

URGENT: VB.NET - Need to update datatable column values with XMLReader.ReadToFollowing(String) method

Hi everyone,

In my application, I create a datatable in code and then fill one column with values.
I need to subsequently update the rest of the columns in the datatable with values from a XMLReader using the ReadToFollowing(String) method
.
Here is the sample code:

The first part, creating the datatable and filling the first column works fine
-----------------------------------------------------------------------------------------------------------

        Dim datatable1 As New DataTable
        datatable1.Columns.Add("COLUMN1", GetType(System.Double)) '-- row(0)
        datatable1.Columns.Add("COLUMN2", GetType(System.String)) '-- row(1)
        datatable1.Columns.Add("COLUMN3", GetType(System.String)) '-- row(2)
        datatable1.Columns.Add("COLUMN4", GetType(System.String)) '-- row(3)
        datatable1.Columns.Add("COLUMN5", GetType(System.String))  '--row(4)
        datatable1.Columns.Add("COLUMN6", GetType(System.String)) '--row(5)
        datatable1.Columns.Add("COLUMN7", GetType(System.Double)) '--row(6)

        Dim row As DataRow

        Dim reader As XmlReader = XmlReader.Create("C:\SampleXML.xml")
        While reader.ReadToFollowing("SampleColumn1")
            row = datatable1.NewRow
            row("COLUMN1") = reader.ReadInnerXml()
            datatable1.Rows.Add(row)
            datatable1.AcceptChanges()
        End While

Now, I need to fill the second column in the datatable from the same XML file.
------------------------------------------------------------------------------------------------------------------

        reader = XmlReader.Create("C:\SampleXML.xml")   'Read XML file for second column values
        Dim datatable1row as DataRow

        For each datatable1row as DataRow in datatable1.Rows
                   While reader.ReadToFollowing("SampleColumn2")
                        datatable1row("COLUMN2") = reader.ReadInnerXML()
                        datatable1.AcceptChanges()
        End While

        reader.Close()

===================================

The code to update the second datatable column with consecutive values from the XML file isn't working correctly.

Thanks!
Avatar of Scott McDaniel (EE MVE )
Scott McDaniel (EE MVE )
Flag of United States of America image

Please stop prefacing all of your question with URGENT or EMERGENCY. This is a web-based forum staffed ENTIRELY by VOLUNTEERS, and we are not here to be at your beck and call.

If you want to have immediate, on-demand assistance I'd suggest you use the Live platform, or hire one of the Experts here (not me).
ASKER CERTIFIED SOLUTION
Avatar of Shaun Vermaak
Shaun Vermaak
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Eric Burton

ASKER

Thank you very much for your help!