Writing xml file from dataset different than the original

B

Bmack500

Hello all.
I'm reading the data from an XML file similiar to below, using the
code below. When the
file is edited in the datagridview and then re-written, it doesn't
write the xml
file as it was originally written.

So what am I doing wrong? My code and samples are below. Any help
would be greatly appreciated!!

VISUAL STUDIO 2005
..NET 2.0 FRAMEWORK, VB.NET CODE

Declare a bindings source, a dataset, a binding navigator, and set up
a datagridview where the
data is displayed & edited

'now associate them

bndgSrc1.DataSource = ds
dgvConfig.DataSource = bndgSrc1
binNav1.BindingSource = bndgSrc1


'Now read the xml file into the dataset &
ds.readxml(filename)
ds.ReadXml(My.Settings.configFile)
bndgSrc1.DataMember = "pnum"
bndgSrc1.ResetBindings(False)



I save the edited info as below:

dgvConfig.EndEdit()
bndgSrc1.EndEdit()
If ds.HasChanges Then
ds.AcceptChanges()
ds.WriteXml(My.Settings.configFile, XmlWriteMode.WriteSchema)
End If
bndgSrc1.ResetBindings(False)



!<ORIGINAL XML FILE SAMPLE BELOW>

<?xml version="1.0" standalone="yes"?>
<config>
<workstations>
<ws>pcnamexxx</ws>
<ws>pcnamexxx</ws>
</workstations>
<patches>
<pnum>1837</pnum>
</patches>
<users>
<uid>user3</uid>
<uid>user4</uid>
</users>
<ad>
<ou>OU=firstlevel,OU=secondlevel,DC=GOOGLE,DC=COM</ou>
<ou>OU=anotherou,OU=yetanother,DC=GOOGLE,DC=COM</ou>
</ad>
</config>

If I delete all the records, I just get the "<patches /> remnant left
behind:

!<SAVED (ALL PATCHES RECORDS DELETED) XML FILE SAMPLE BELOW>

<?xml version="1.0" standalone="yes"?>
<config>
<workstations>
<ws>pcnamexxx</ws>
<ws>pcnamexxx</ws>
</workstations>
<patches />
<users>
<uid>user3</uid>
<uid>user4</uid>
</users>
<ad>
<ou>OU=firstlevel,OU=secondlevel,DC=GOOGLE,DC=COM</ou>
<ou>OU=anotherou,OU=yetanother,DC=GOOGLE,DC=COM</ou>
</ad>
</config>

If I enter a new record, it doesn't nest it within the parent, as
below:

!<SAVED (NEW PATCHES RECORD INSERTED) XML FILE SAMPLE BELOW>

<?xml version="1.0" standalone="yes"?>
<config>
<workstations>
<ws>pcnamexxx</ws>
<ws>pcnamexxx</ws>
</workstations>
<patches>
<pnum>1837</pnum>
</patches>
<pnum>1838</pnum>
<users>
<uid>user3</uid>
<uid>user4</uid>
</users>
<ad>
<ou>OU=firstlevel,OU=secondlevel,DC=GOOGLE,DC=COM</ou>
<ou>OU=anotherou,OU=yetanother,DC=GOOGLE,DC=COM</ou>
</ad>
</config>
 
C

Cor Ligthert [MVP]

Bmack,

I assume that the writting is in a method, how does that method know about
the existence of ds.

Maybe it is easier if you write in top of your program
Option Strict On.

Now Net is taken its own decissions what it will take on runtime, which can
be the wrong one.

Cor
 
B

Bmack500

Bmack,

I assume that the writting is in a method, how does that method know about
the existence of ds.

Maybe it is easier if you write in top of your program
Option Strict On.

Now Net is taken its own decissions what it will take on runtime, which can
be the wrong one.

Cor

Option strict on is enabled within VStudio 2005. DS is a global
variable; I've put in the most relevant code. Yes, the writing is in a
method. Perhaps using a global was a bit lazy, I'll change it to pass
the parameters but I don't think that'll make a difference with this.
However, I don't quite understand your statement "Now Net is taken its
own decisions what it will take on runtime, which can be the wrong
one."
Could you please clarify? Any help is greatly appreciated. I also see
that I've ds.readxml in there twice, which obviously I'll take out.
but it's referring to the same file.
 
C

Cor Ligthert [MVP]

BMack,

Did you try it already with a path description instead of the one you get
from your config file. In my idea are you by doing it the problem only more
complex. Beside that I don't see why you don't do an endedit on this
dataset, can I not see anything wrong.

Assuming that there were changes in the grid.

Is there something special that you show us this kind of code?
dgvConfig.DataSource = bndgSrc1

I don't see it related to your question

Cor
 
C

Cor Ligthert [MVP]

Correction wrong typing
In my idea are you by doing it the problem only more complex.
change for
In my idea are you: (by doing it in the way as you do now) making the
solution for us more difficult to see.

Cor
 

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