|
dev
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Writing xml file from dataset different than the originalI'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> 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 Show quote "Bmack500" <brett.m***@gmail.com> schreef in bericht news:1173474430.496753.145800@t69g2000cwt.googlegroups.com... > 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> >
Show quote
On Mar 11, 2:38 am, "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> Option strict on is enabled within VStudio 2005. DS is a globalwrote: > 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 > > "Bmack500" <brett.m***@gmail.com> schreef in berichtnews:1173474430.496753.145***@t69g2000cwt.googlegroups.com... > > > 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> 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. 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 questionCor Show quote "Bmack500" <brett.m***@gmail.com> schreef in bericht news:1173638732.631497.33340@h3g2000cwc.googlegroups.com... > On Mar 11, 2:38 am, "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> > wrote: >> 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 >> >> "Bmack500" <brett.m***@gmail.com> schreef in >> berichtnews:1173474430.496753.145***@t69g2000cwt.googlegroups.com... >> >> > 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> > > 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. > 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 Show quote "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> schreef in bericht news:enPrAKBZHHA.3256@TK2MSFTNGP04.phx.gbl... > 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 > > "Bmack500" <brett.m***@gmail.com> schreef in bericht > news:1173638732.631497.33340@h3g2000cwc.googlegroups.com... >> On Mar 11, 2:38 am, "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> >> wrote: >>> 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 >>> >>> "Bmack500" <brett.m***@gmail.com> schreef in >>> berichtnews:1173474430.496753.145***@t69g2000cwt.googlegroups.com... >>> >>> > 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> >> >> 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. >> > > |
|||||||||||||||||||||||