lrehotmail
Programmer
Please forgive me, if you found I asked the same question twice. The first time was in the ASP.NET forum but there was no answer, that why I ask it again here.
I tried to add new record into the dataset, which fetch the schema from the XML file and then write back with a new record into the XML file. But the existing records are purged and the new record will be recorded in a XML file only.
Does anyone know how it works, please?
Note[/]: "id" is an attribute of the "product" element. And it can appear as an attribute for the "product" element, which I still don't understand how it works, but it works!
Thanks in advance!
I tried to add new record into the dataset, which fetch the schema from the XML file and then write back with a new record into the XML file. But the existing records are purged and the new record will be recorded in a XML file only.
Does anyone know how it works, please?
Note[/]: "id" is an attribute of the "product" element. And it can appear as an attribute for the "product" element, which I still don't understand how it works, but it works!
Code:
Dim xmlDS = New DataSet
xmlDS.ReadXml("d:\writeFolder\file01.xml")
Dim newRow As DataRow
newRow = xmlDS.Tables("products").NewRow
newRow.Item("id") = Request("txtProduct")
newRow.Item("product") = Request("txtProdName")
newRow.Item("description") = Request("txtDescription")
newRow.Item("unitPrice") = Request("txtUPrice")
newRow.Item("inventory") = Request("txtInventory")
newRow.Item("operator") = Request("txtOperator")
xmlDS.Tables("products").Rows.Add(newRow)
dgrShowXml.DataSource = xmlDS
dgrShowXml.DataBind()
xmlDS.WriteXml("d:\writeFolder\file01.xml")
Thanks in advance!