Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't add new node into XML file - ASP.NET VB

Status
Not open for further replies.

lrehotmail

Programmer
Nov 18, 2002
15
AU
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!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top