misslinda454
asked on
Append datarow to the end of an xml file
I am writing in VB.NET and working with an ADO.NET dataset.
In most cases I can use the dataSet.WriteXML method to backup my dataset as an xml file. But for the most part I don't want to have to rewrite the xml file everytime I add a new row to the dataset. How would I go about appending just the new row data to the end of the xml file or do I just have to rewrite it everytime?
In most cases I can use the dataSet.WriteXML method to backup my dataset as an xml file. But for the most part I don't want to have to rewrite the xml file everytime I add a new row to the dataset. How would I go about appending just the new row data to the end of the xml file or do I just have to rewrite it everytime?
J_Make sorry, i've missed it, it's all right with your Schema
upppssss....wrong topic, sorry guys ;)
ASKER
Would you happen to have an example of appending a datarow to the data set? Does this recognize the schema for you or do you have to take each field and know the schema? If you use the get changes method are you still only writing the changed rows or are you still re-writing the whole xml doc .. if it only goes through and writes the changes that would be perfect!
Well, MSDN has this example:
Private Sub UpdateDataSet(ByVal myDataSet As DataSet)
' Check for changes with the HasChanges method first.
If Not myDataSet.HasChanges(DataR owState.Mo dified) Then Exit Sub
' Create temporary DataSet variable.
Dim xDataSet As DataSet
' GetChanges for modified rows only.
xDataSet = myDataSet.GetChanges(DataR owState.Mo dified)
' Check the DataSet for errors.
If xDataSet.HasErrors Then
' Insert code to resolve errors.
End If
' After fixing errors, update the data source with the DataAdapter
' used to create the DataSet.
myOleDbDataAdapter.Update( xDataSet)
End Sub
Regards,
Mike Sharp
Private Sub UpdateDataSet(ByVal myDataSet As DataSet)
' Check for changes with the HasChanges method first.
If Not myDataSet.HasChanges(DataR
' Create temporary DataSet variable.
Dim xDataSet As DataSet
' GetChanges for modified rows only.
xDataSet = myDataSet.GetChanges(DataR
' Check the DataSet for errors.
If xDataSet.HasErrors Then
' Insert code to resolve errors.
End If
' After fixing errors, update the data source with the DataAdapter
' used to create the DataSet.
myOleDbDataAdapter.Update(
End Sub
Regards,
Mike Sharp
ASKER
I knew how to update a DB using a data adapter and dataset ... I didn't know how to add a row to the xml document .. I know how to append a child node at a time just not a row - a collection of nodes for lack of better words ..
So if I had a row that had data in Field1, Field2, Field3 .. and I wanted to add that row to the bottom of the data set with a doc that looked like ..
<datatable1>
<row>
<field1> a </field1>
<field2> b </field2>
<field3> c </field3>
</row>
.....how to append next row to end?????
</datatable>
So if I had a row that had data in Field1, Field2, Field3 .. and I wanted to add that row to the bottom of the data set with a doc that looked like ..
<datatable1>
<row>
<field1> a </field1>
<field2> b </field2>
<field3> c </field3>
</row>
.....how to append next row to end?????
</datatable>
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect! Thank you very much!
changedDataSet = myDataSet.GetChanges(DataR
then write the changedDataSet to an XML document. If there's only a single row in it, you can then append the appropriate node to the previous XML document. Otherwise you'd have to iterate over the changed nodes, appending each one. Not sure if that saves you anything, though, unless the data is very large and you keep the original XML in memory.
Regards,
Mike Sharp