Code for Creating xml file from a Dataset in

You can use WriteXml method of the Dataset for saving the dataset data in xml format. And you can call ReadXml method for getting dataset from the xml file. In this article we will discuss about both methods.

Create xml file from a dataset


Private Sub WriteXML_fromDS()
        Dim Conn As New SqlClient.SqlConnection("Put here your Connection string")
        Dim StrQuery As String = "Your select query"
        Dim ds As New DataSet
        Dim dadapter As New SqlClient.SqlDataAdapter("select * from sales ", Conn)
        ds.WriteXml("put xml file path with file name")
End Sub

Get dataset from a Xml file

In the following example we are creating a dataset from the specified xml file see this:

Private sub ReadXMLIntoDS()
   Dim ds as Dataset
   ds.readXml("xml fie path")
End Sub