ASP 101 - Active Server Pages 101 db_search.aspx
<%@ Page Language="VB" %>
<%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<script language="VB" runat="server">
	Sub btnSearch_OnClick(sender as Object, e as EventArgs)
		Dim objConnection As SqlConnection
		Dim objCommand    As SqlCommand
		Dim objAdapter    As SqlDataAdapter
		Dim objDataSet    As DataSet
		Dim strSearch     As String
		Dim strSQLQuery   As String
		' Get Search 
		strSearch = txtSearch.Text
		' If there's nothing to search for then don't search
		' o/w build our SQL Query and execute it.
		If Len(Trim(strSearch)) > 0 Then
			' Set up our connection.
			objConnection = New SqlConnection("Data Source=10.2.2.133;" _
	& "Initial Catalog=samples;User Id=samples;Password=password;" _
	& "Connect Timeout=15;Network Library=dbmssocn;")
			' Set up our SQL query text.
			strSQLQuery = "SELECT first_name + ' ' + last_name AS Name, Sales " _
				& "FROM sample " _
				& "WHERE last_name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
				& "OR first_name LIKE '%" & Replace(strSearch, "'", "''") & "%' " _
				& "ORDER BY last_name;"
			' Create new command object passing it our SQL query
			' and telling it which connection to use.
			objCommand = New SqlCommand(strSQLQuery, objConnection)
			' Get a DataSet to bind the DataGrid to
			objAdapter = New SqlDataAdapter(objCommand)
			objDataSet = New DataSet()
			objAdapter.Fill(objDataSet)
			' DataBind DG to DS
			dgSearch.DataSource = objDataSet
			dgSearch.DataBind()
			objConnection.Close()
		Else
			txtSearch.Text = "Enter Search Here"
		End If
	End Sub
</script>
<html>
<head>
  <title>ASP.NET Database Search Sample</title>
</head>
<body>
<form runat="server">
<p>Search our sample db by first or last name.  (% returns all)</p>
<asp:TextBox id="txtSearch" runat="server" />
<asp:Button id="btnSearch" runat="server"
	Text    = "Search"
	OnClick = "btnSearch_OnClick"
/>
<p>[Try 'am' or 'er' for an example]</p>
<!-- Plain vanilla DataGrid... format it as you like. -->
<asp:DataGrid id="dgSearch" runat="server"
	HeaderStyle-Font-Bold="True"
/>
</form>
<hr />
<p>
Click <a href="http://www.asp101.com/samples/db_search_aspx.asp">here</a>
to read about and download the source code.
</p>
</body>
</html>