Partial Public Class _Default Inherits System.Web.UI.Page Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 'If there is no postback (e.g. the first time the page loads), nothing 'special needs to be done. But... If IsPostBack Then Dim myDatabaseConnection As SqlClient.SqlConnection = Nothing Dim myCommand As SqlClient.SqlCommand = Nothing Dim partsDataSet As DataSet = Nothing Try ErrorLabel.Visible = False ListAllButton.Visible = False AllPartsLabel.Visible = True Dim connectionString As String = _ ConfigurationManager.ConnectionStrings("PartsConnectionString").ConnectionString myDatabaseConnection = New SqlClient.SqlConnection(connectionString) myCommand = New SqlClient.SqlCommand() 'Set up to use a stored procedure: myCommand.CommandType = CommandType.StoredProcedure myCommand.Connection = myDatabaseConnection myCommand.CommandText = "SelectAllParts" 'Use a DataAdapter to execute the stored procedure and 'get the results into the GridView: Dim adapter As New SqlClient.SqlDataAdapter(myCommand) partsDataSet = New DataSet myDatabaseConnection.Open() adapter.Fill(partsDataSet) myDatabaseConnection.Close() myDatabaseConnection.Dispose() PartsGridView.DataSource = partsDataSet PartsGridView.DataBind() PartsGridView.Visible = True Catch exception As System.Data.SqlClient.SqlException ErrorLabel.Visible = True Catch exception As Exception ErrorLabel.Visible = True Finally 'Do cleanup here: myCommand = Nothing partsDataSet = Nothing If Not myDatabaseConnection Is Nothing AndAlso _ myDatabaseConnection.State = ConnectionState.Open Then myDatabaseConnection.Close() myDatabaseConnection.Dispose() End If End Try End If End Sub End Class