Updating XML through strongly typed dataset

  • Thread starter Thread starter Big D
  • Start date Start date
B

Big D

Hi all,

I have an xml file that I load into a strongly typed dataset via the ReadXML
method of the dataset. I then want to add a new row to the dataset and save
it back to disk.

Each row in the dataset is defined as an "entry", so I have a entryDataRow
member of my Entries dataset. However, I can't seem to figure out how to
create a new instance of an entryDataRow, modify it and add it to the
dataset. I can't find anything in my books, or MSDN about this subject...
maybe I am going about it the wrong way?

I'm used to doing this sort of thing for databases through a sqlDataAdapter,
and using "update" to modify the datasource, but I don't get how to have an
adapter to the XML file.

Your help is greatly appreciated!

-D

psudo - code of what I'm wanting to do:

dim ds as new Entries
ds.readXML("theXMLFile.xml")
dim dr as new Entries.entryRow
dr.item1 = "blah"
dr.Item2 = "blah"
ds.rows.add(dr)
ds.saveXML("theXMLFile.xml")
 
Hi Big,

DataRow is part of a DataTable and not of a DataSet.
You should do something like
YourDataSet.entriesDataRow row = dataset.table.NewentriesRow();
row.Item1 = ...
....
dataset.table.AddentriesRow(row);
 
Hi BigD

As answer direct in your code asuming there is only one table in your XML
file

roughly typed.
\\\
dim ds as new dataset
ds.readXML("theXMLFile.xml")
dim dr as datarow =ds.tables(0).newrow
dr.item1 = "blah"
dr.Item2 = "blah" ds.tables(0).rows.add(dr)
ds.saveXML("theXMLFile.xml")
///

I hope this helps a little bit?

Cor
 
Back
Top