EDN Admin
Well-known member
Greetings,<br/> <br/> On my vb.net application main screen I currently use the xmldatadocument dataset to read in a user selected xml file which is then bound to the datagridview, allowing the user to view the xml data.<br/> <br/> A dialog allows the user to add a new element by opening the xmldocument, creating an xmlelement finally appending the xmlelement to the xmldocument.<br/> <br/> The datagridview will not reflect the changes as the datasource the dataset -> datatable table has not been updated only the xml document has the saved changes.<br/> <br/> I did think after saving the xml document to reset the datasource of the datagridview, however I was wondering can I convert the xmlelement somehow to a datarow and then just add the single datarow to the bound datatable?<br/> <br/> So to summarise can I use an xmlelement to be added as a datarow to a dataset -> datatable?<br/> <br/> Updated: Code used to add new xmlelement to file how can it be used to updata datatable?<br/> <br/>
<pre> Dim quotedoc As New XmlDocument
Load xml data into the instance of xmldocument created above
quotedoc.Load(cQuoteFileName)
Create the root node element i.e. quotefile for a NEW quote
Dim xmlQuoteEl As XmlElement = quotedoc.CreateElement("quote")
Create nodes under the root element
xmlQuoteEl.InnerXml = "<date></date><author></author><category></category><text></text>"
Set details for quote
xmlQuoteEl.Item("date").InnerText = dtpQuoteDate.Value.ToString("dd MMMM yyyy")
xmlQuoteEl.Item("author").InnerText = txtAuthor.Text
xmlQuoteEl.Item("category").InnerText = cboCategory.SelectedItem.ToString
xmlQuoteEl.Item("text").InnerText = txtQuote.Text
append the whole element to the whole damn document.
quotedoc.DocumentElement.AppendChild(xmlQuoteEl)
save the document now!
quotedoc.Save(cQuoteFileName)[/code]
<br/> <br/> Thanks<br/> Rob
View the full article
<pre> Dim quotedoc As New XmlDocument
Load xml data into the instance of xmldocument created above
quotedoc.Load(cQuoteFileName)
Create the root node element i.e. quotefile for a NEW quote
Dim xmlQuoteEl As XmlElement = quotedoc.CreateElement("quote")
Create nodes under the root element
xmlQuoteEl.InnerXml = "<date></date><author></author><category></category><text></text>"
Set details for quote
xmlQuoteEl.Item("date").InnerText = dtpQuoteDate.Value.ToString("dd MMMM yyyy")
xmlQuoteEl.Item("author").InnerText = txtAuthor.Text
xmlQuoteEl.Item("category").InnerText = cboCategory.SelectedItem.ToString
xmlQuoteEl.Item("text").InnerText = txtQuote.Text
append the whole element to the whole damn document.
quotedoc.DocumentElement.AppendChild(xmlQuoteEl)
save the document now!
quotedoc.Save(cQuoteFileName)[/code]
<br/> <br/> Thanks<br/> Rob
View the full article