Imports System.Data.SqlClient

Public Class XmlTest

    Private Sub cmdWrite_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdWrite.Click

        ' Define ADO.NET objects.
        Dim SQL As String = "SELECT * FROM Products"
        Dim Connect As String = "Data Source=localhost;Integrated Security=True;" & _
         "Initial Catalog=Northwind;"

        Dim con As New SqlConnection(Connect)
        Dim cmd As New SqlCommand(SQL, con)
        Dim adapter As New SqlDataAdapter(cmd)

        Dim dsNorthwind As New DataSet()


        con.Open()

        adapter.Fill(dsNorthwind, "Products")

        con.Close()

        dsNorthwind.WriteXmlSchema(txtFile.Text & ".xsd")
        dsNorthwind.WriteXml(txtFile.Text)

        MessageBox.Show("File created. You can now read it.")
    End Sub

    Private Sub cmdRead_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdRead.Click
        Dim dsNorthwind As New DataSet()
        If System.IO.File.Exists(txtFile.Text) Then
            dsNorthwind.ReadXml(txtFile.Text)
            grid.DataSource = dsNorthwind.Tables(0)
        Else
            MessageBox.Show("You need to create this file first.")
        End If
    End Sub

End Class