Imports System.Data.SqlClient
Imports System.Data
Imports System.Web.Configuration

Partial Class DataBinding
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        ' Connection string można odnaleźć i zmienić w pliku web.config.
        Dim ConnectionString As String = WebConfigurationManager.ConnectionStrings("Northwind").ConnectionString

        Dim con As New SqlConnection(ConnectionString)
        Dim SQL As String = "SELECT ProductID, ProductName, QuantityPerUnit, UnitPrice, UnitsInStock FROM Products"
        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()
        ' Wiązanie tabeli.
        gridDB.DataSource = dsNorthwind.Tables("Products")
        ' Wiązanie listy rozwijanej z polem ProductName.
        lstName.DataSource = dsNorthwind.Tables("Products")
        lstName.DataTextField = "ProductName"
        ' Wiązanie listy pól wyboru z polem QuantityPerUnit.
        lstQuantity.DataSource = dsNorthwind.Tables("Products")
        lstQuantity.DataTextField = "QuantityPerUnit"
        ' Przenoszenie informacji z obiektu DataSet do kontrolek.
        Me.DataBind()
    End Sub
End Class
