Imports System.Data.SqlClient

Public Class XmlTest

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

        ' Definiowanie obiektów ADO.NET.
        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("Plik utworzono. Teraz można go wczytać.")
    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("Najpierw trzeba utworzyć potrzebny plik.")
        End If
    End Sub

End Class