XML - Addnew record e salva in file esterno





Imports System
Imports System.Data

Module DataSetWriter
Sub Main()
Dim MyDS As New DataSet()
MyDS.ReadXmlSchema("../Books.xsd")
MyDS.ReadXml("../Books.xml")

' If we don't call AcceptChanges(), the DataSet thinks

' that _all_ data read from disk is "new". We only want

' the row that we add programmatically to appear as "new".

MyDS.AcceptChanges()

Console.WriteLine("Data loaded from disk.")

Dim NewBook As DataRow = MyDS.Tables("Book").NewRow()
NewBook("ISBN") = "1861008066"
NewBook("Title") = "Professional ADO.NET"
NewBook("Price") = 49.99
MyDS.Tables("Book").Rows.Add(NewBook)

' With the new row added, the DataSet is storing

' "change" data. We can store this change as a DiffGram.

MyDS.WriteXml("../Books_Changes.xml", XmlWriteMode.DiffGram)

' Now commit the changes and write the entire DataSet.

MyDS.AcceptChanges()
MyDS.WriteXml("../Books_New.xml", XmlWriteMode.IgnoreSchema)

Console.WriteLine("Changes and entire DS have been written.")
Console.ReadLine()

End Sub
End Module










( xmladdnewrecordesalvainfileesterno.html )- by Paolo Puglisi - Modifica del 17/12/2023