Search From TextBox - Display With Datagrid

 
 
Just copy and paste this code into a new blank page. Change the Database name, UID and password. It uses the pubs database with SQL Server and save it as a '.aspx' page. This code will, upon loading the page, present you with a Text Box, where you will enter a last name. In this particular search, the lastname field in the database is what is searched. Then, based on the search criteria, will search for all authors with the last name chosen, displaying all items in a Datagrid. As you will also see, if you type in a name that is not actually listed in the table, you will see how to handle this problem with an if/then statement.
 
 
  1. SQL Server

  2.  

  3. <%@ Import Namespace="System.Data" %>

  4. <%@ Import Namespace="System.Data.SqlClient" %>

  5. <html>

  6. <head>

  7. <script language="VB" runat="server">

  8. Sub doQuery(Source as Object, E as EventArgs)

  9.         Dim DS As DataSet

  10.         Dim MyConnection As SqlConnection

  11.         Dim MyCommand As SqlDataAdapter

  12.         Dim strName as string

  13.         strName=Name.Text

  14.         Label1.Text="You searched for : "   strName

  15.         Dim MySQL as string

  16.         MySQL="select * from Authors where au_lname ='" 
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 25th Aug 2007
  Rating : No Rating
  Accessed  :  7279
  Submitted by :  loopsnlogic
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related ASP.NET Source Codes
  • Spring
  • Wraps a string to a given number of characters using a string break character
  • Uppercase the first character of each word in a string
  • Make a string's first character uppercase
  • Strip whitespace (or other characters) from the beginning and end of a string

  • Copyright © 2013 VisualBuilder. All rights reserved

    Warning: Unknown(): write failed: Disk quota exceeded (122) in Unknown on line 0

    Warning: Unknown(): Failed to write session data (files). Please verify that the current setting of session.save_path is correct (/tmp) in Unknown on line 0