Question add a row to datagridview by XML

Ron Miel

Member
Joined
Apr 9, 2011
Messages
16
Programming Experience
10+
I have a datasgridview. I can populate it from an XML file like this:

VB.NET:
  Public ds As New DataSet
   ...
   Dim xmlFile As XmlReader
   xmlFile = XmlReader.Create("products.xml", New XmlReaderSettings())
   ds.ReadXml(xmlFile)
   dg_products.DataSource = ds.Tables(0)

this is linked to the file, so that if I change the data manually, it wil be saved in the file.

Now, I perform a webrequest, and get a webresponse. It is one record in XML, the same format as the file.

I want to add the new record to the datagridview, and the linked file. What is the syntax for doing this?
 
You can't, but you can create a new row with values and add it manually to the DataTable.
dt.Rows.Add("A", "B", "C")

These values can of course come from the XDocument node values, like the "name" value in example post 8.
 
me said:
You can't
To elaborate on that. You can by using Xdocument.CreateReader that returns a XmlReader, which can be used as input for DataSet/DataTable.ReadXml, but that would have same effect as using ReadXml(inputStream) in the first place, which as you've explained can't work for you.
 
Back
Top