Imports System.Data.SqlClient Imports System.Configuration Public Class CatMenuComment Inherits System.Web.UI.Page #Region " Web Form Designer Generated Code " 'This call is required by the Web Form Designer. Private Sub InitializeComponent() End Sub Protected WithEvents MyCatList As System.Web.UI.WebControls.DataList Protected WithEvents homeImage As System.Web.UI.HtmlControls.HtmlImage 'NOTE: The following placeholder declaration is required by the Web Form Designer. 'Do not delete or move it. Private designerPlaceholderDeclaration As System.Object Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init 'CODEGEN: This method call is required by the Web Form Designer 'Do not modify it using the code editor. InitializeComponent() End Sub #End Region Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Put user code to initialize the page here REM The user has not made a menu selection. REM Show the home page image. homeImage.Visible = True REM Get the Menu List Try REM Retrieve the connection string from the CS application variable Dim CS As String = ConfigurationSettings.AppSettings("CS") Dim SqlConnection1 As New SqlConnection(CS) REM Open the connection object SqlConnection1.Open() REM Assign a SQL statement and a connection object to the command object Dim objCM1 As SqlCommand objCM1 = New SqlCommand("SELECT * FROM Categories", SqlConnection1) objCM1.CommandType = CommandType.Text REM Use the DataReader object returned as the source for the REM MyCatList List control. Dim objDR1 As SqlDataReader objDR1 = objCM1.ExecuteReader(CommandBehavior.CloseConnection) REM Bind the MyCatList List control to the DataReader object. MyCatList.DataSource = objDR1 MyCatList.DataBind() REM If there is a problem with the SQL Server database REM redirect the user to the error page. Catch Ex As SqlException Dim eMSG As String = Ex.Message Dim eHL As String = Ex.HelpLink Dim eST As String = Ex.StackTrace Dim eTS As String = Ex.ToString REM Encode the QueryString to pass the exception values to the error page Response.Redirect("CustomErrorSQL.aspx?" & _ "eMSG=" & System.Web.HttpUtility.UrlEncode(eMSG) & _ "&eHL=" & System.Web.HttpUtility.UrlEncode(eHL) & _ "&eST=" & System.Web.HttpUtility.UrlEncode(eST) & _ "&eTS=" & System.Web.HttpUtility.UrlEncode(eTS)) End Try End Sub End Class