StellaIndigo
IS-IT--Management
Hi Everyone
I'm having problems reading a datafile full of XML data into a dataset then posting it back to a database table (access).
Here's my code,
None of the code generates any error during execution. The XML data does not seem to load into the dataset. Only the table I use for the inital select exists and the data is not loadd into that either.
the xml file looks like this
This loads into my table called tblTracking in the Access database if I use Application.ImportXML... within Access.
Main question, why doesn't the XML file load into the dataset?
Any ideas or help welcome.
Regards
Stella
There are 10 types of people in the world. Those that understand binary and those that don't.
I'm having problems reading a datafile full of XML data into a dataset then posting it back to a database table (access).
Here's my code,
Code:
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim cnTrackConnection As OleDb.OleDbConnection
Dim daTrackDataAdaptor As OleDb.OleDbDataAdapter
Dim dtTrackDataTable As New DataTable
Dim dsTrackDataSet As DataSet
Dim strConnectionString As String
Dim xmlStream As New System.IO.StreamReader("c:\temp\MyXMLFile.xml")
Dim reader As New System.Xml.XmlTextReader(xmlStream)
Dim command As OleDb.OleDbCommand
strConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\temp\MyDataBase.mdb"
cnTrackConnection = New OleDb.OleDbConnection(strConnectionString)
dsTrackDataSet = New DataSet("tblTracking")
cnTrackConnection.Open()
daTrackDataAdaptor = New OleDb.OleDbDataAdapter("select * from tblTracking", strConnectionString)
daTrackDataAdaptor.Fill(dsTrackDataSet)
dsTrackDataSet.ReadXml(reader, XmlReadMode.IgnoreSchema)
MsgBox("Tables in set " & dsTrackDataSet.Tables.Count)
For Each dtTrackDataTable In dsTrackDataSet.Tables
MsgBox("Rows in table 0 " & dtTrackDataTable.Rows.Count())
Next
dsTrackDataSet.AcceptChanges()
command = New OleDb.OleDbCommand("insert into tblTracking (customer_number) values (?)", cnTrackConnection)
command.Parameters.Add("customer_number", OleDb.OleDbType.Char, 6, "customer_number")
daTrackDataAdaptor.InsertCommand = command
command = New OleDb.OleDbCommand("UPDATE tblTracking SET customer_number = @CustomerID ", cnTrackConnection)
command.Parameters.Add("@CustomerID", OleDb.OleDbType.Char, 5, "customer_number")
daTrackDataAdaptor.UpdateCommand = command
daTrackDataAdaptor.Update(dsTrackDataSet)
cnTrackConnection.Close()
daTrackDataAdaptor.Dispose()
dtTrackDataTable.Dispose()
cnTrackConnection = Nothing
daTrackDataAdaptor = Nothing
dtTrackDataTable = Nothing
End Sub
None of the code generates any error during execution. The XML data does not seem to load into the dataset. Only the table I use for the inital select exists and the data is not loadd into that either.
the xml file looks like this
Code:
<dataroot>
<tblTracking>
<customer_number>770010</customer_number>
<order_number>Y8762E</order_number>
<tray_number></tray_number>
<reference></reference>
<ordered_date>2006-08-24T11:00:00Z</ordered_date>
<expected_despatch_date>2006-08-24</expected_despatch_date>
<revised_despatch_date></revised_despatch_date>
<actual_despatch_date></actual_despatch_date>
<location_code> </location_code>
<location_description>Production Processing</location_description>
<order_type>F</order_type>
</tblTracking>
<tblTracking>
<customer_number>028617</customer_number>
<order_number>L7240I</order_number>
<tray_number>0004</tray_number>
<reference>MISS H MCALPINE 007767</reference>
<ordered_date>2006-11-02T14:01:00Z</ordered_date>
<expected_despatch_date>2006-11-07</expected_despatch_date>
<revised_despatch_date></revised_despatch_date>
<actual_despatch_date>2006-11-06T12:30:00Z</actual_despatch_date>
<location_code>Z</location_code>
<location_description>Despatched</location_description>
<order_type>G</order_type>
</tblTracking>
<tblTracking>
<customer_number>101101</customer_number>
<order_number>M5233Q</order_number>
<tray_number>0004</tray_number>
<reference>FORD S A163395</reference>
<ordered_date>2006-11-07T11:44:00Z</ordered_date>
<expected_despatch_date>2006-11-08</expected_despatch_date>
<revised_despatch_date>2006-11-08</revised_despatch_date>
<actual_despatch_date>2006-11-08T10:58:00Z</actual_despatch_date>
<location_code>Z</location_code>
<location_description>Despatched</location_description>
<order_type>G</order_type>
</tblTracking>
</dataroot>
This loads into my table called tblTracking in the Access database if I use Application.ImportXML... within Access.
Main question, why doesn't the XML file load into the dataset?
Any ideas or help welcome.
Regards
Stella
There are 10 types of people in the world. Those that understand binary and those that don't.