Eric Burton
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("CO LUMN1", GetType(System.Double)) '-- row(0)
datatable1.Columns.Add("CO LUMN2", GetType(System.String)) '-- row(1)
datatable1.Columns.Add("CO LUMN3", GetType(System.String)) '-- row(2)
datatable1.Columns.Add("CO LUMN4", GetType(System.String)) '-- row(3)
datatable1.Columns.Add("CO LUMN5", GetType(System.String)) '--row(4)
datatable1.Columns.Add("CO LUMN6", GetType(System.String)) '--row(5)
datatable1.Columns.Add("CO LUMN7", GetType(System.Double)) '--row(6)
Dim row As DataRow
Dim reader As XmlReader = XmlReader.Create("C:\Sampl eXML.xml")
While reader.ReadToFollowing("Sa mpleColumn 1")
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:\Sampl eXML.xml") 'Read XML file for second column values
Dim datatable1row as DataRow
For each datatable1row as DataRow in datatable1.Rows
While reader.ReadToFollowing("Sa mpleColumn 2")
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!
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("CO
datatable1.Columns.Add("CO
datatable1.Columns.Add("CO
datatable1.Columns.Add("CO
datatable1.Columns.Add("CO
datatable1.Columns.Add("CO
datatable1.Columns.Add("CO
Dim row As DataRow
Dim reader As XmlReader = XmlReader.Create("C:\Sampl
While reader.ReadToFollowing("Sa
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:\Sampl
Dim datatable1row as DataRow
For each datatable1row as DataRow in datatable1.Rows
While reader.ReadToFollowing("Sa
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!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you very much for your help!
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).