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

        ' You can find this connection string (and change it)
        ' in the web.config file.
        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()
        ' Bind the grid.
        gridDB.DataSource = dsNorthwind.Tables("Products")
        ' Bind the drop-down list to the ProductName field.
        lstName.DataSource = dsNorthwind.Tables("Products")
        lstName.DataTextField = "ProductName"
        ' Bind the checkbox list to the QuantityPerUnit field.
        lstQuantity.DataSource = dsNorthwind.Tables("Products")
        lstQuantity.DataTextField = "QuantityPerUnit"
        ' Move the information from the DataSet into the controls.
        Me.DataBind()
    End Sub
End Class
