ASP 101 - Active Server Pages 101 db_simple.aspx
<%@ Page Language="VB" EnableViewState="False" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "System.Data.SQLClient" %>
<script language="VB" runat="server">
	Sub Page_Load(sender As Object, e As EventArgs)
		Dim myConnection As SqlConnection 
		Dim myCommand    As SqlCommand
		Dim myDataReader As SqlDataReader
		' Create a new Connection object that connects to our SQL Server.
		' It's running on a separate machine located at the IP address
		'  The name of the database is "samples".
		myConnection = New SqlConnection("Data Source=;" _
			& "Initial Catalog=samples;" _
			& "User Id=samples;Password=password;")
		' Create a new Command object that uses the Connection object we
		' just created and selects all the records from our "scratch" table.
		myCommand = New SqlCommand("SELECT * FROM scratch;", myConnection)
		' Open the connection to the database
		' Use the ExecuteReader method of the Command object to execute
		' our query and return the results via a DataReader
		myDataReader = myCommand.ExecuteReader(CommandBehavior.CloseConnection)
		' Specify the DataReader as the source of the data for our DataGrid
		' and then DataBind to display the data in our DataGrid.
		SimpleDataGrid.DataSource = myDataReader
		' Close our DataReader and Connection
	End Sub
<title>ASP.NET Simple Database Sample</title>
<form runat="server">
	<asp:DataGrid id="SimpleDataGrid" runat="server" />
<hr />
Click <a href="">here</a>
to read about and download the source code.