XML database

G

Graeme Richardson

Hi, I'm working without a database engine, and have created a relational
database using XML files.

I can load the data into a DataSet and then a DataTable with:
Dim ds As DataSet = New DataSet
ds.ReadXML("Program Files\Database\myFile.xml")
Dim dt As DataTable = ds.Tables("myTable")

I can add a new record with:
Dim dr As DataRow = dt.NewRow
dr("field1") = "New Value"
dt.Rows.Add(dr)

What I want to do now is write the changes back to 'myFile.xml'. I tried
dt.AcceptChanges()
ds.AcceptChanges()

but changes/additions aren't written to the file.
How can I get this to work?
Thanks, Graeme.
 
I

Ilya Tumanov [MS]

In fact, DataSet is an in memory database, so you do have a relational
database engine of a sort.

ReadXml() essentially just imports data into the DataSet from XML.
Of course, XML is not updated as you change data in the DataSet - DataSet
is unaware if it's data source.

AcceptChanges() does not update XML (SQL, SQL CE or whatever else data is
coming from).
Instead, it makes new/changed rows current and destroys original rows.
That is, should you change row, you would have two versions of the same row
until you do AcceptChanges() or RejectChanges().

To update the XML, you'll need to export data back to XML using WriteXml().
You can create a new file or overwrite the original.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------
 
G

Graeme Richardson

Thanks Ilya,

Ilya wrote
To update the XML, you'll need to export data back to XML using
WriteXml().
You can create a new file or overwrite the original.

This is what I was hoping to avoid. Several of the tables may have more than
5000 rows which I'm anticipating will take some time to write.

Cheers, Graeme.
 
I

Ilya Tumanov [MS]

If you think about it, there's no good way to search, append or replace
stuff in XML file. May be somebody would invent it soon.

So far, with 5000 records you have no choice but to use old good binary
format combined with database engine.
SQL CE (which is free) might be just right for you. It's about 2 Megs in
size, but XML overhead (50-80%) probably would be noticeably bigger.

As to XML saving speed, yes, it would take some time. Loading it back would
take even more.

Best regards,

Ilya

This posting is provided "AS IS" with no warranties, and confers no rights.

--------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top