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 strongm 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

Status
Not open for further replies.

lrehotmail

Programmer
Nov 18, 2002
15
AU
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!

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