Database Search


Can someone show me the code to search the data in a database whereby the search keywords is provided by users ?

I have 3 search methods and when the user select the method and enter the keywords, the search is carried out within the search method meaning that if the search method is by name, the search is carried out within the name field. After the search button is press, all the record with the matching name will return and display in a datagrid.

Please help me. Thanks.


  • seancampbellseancampbell Pennsylvania, USA
    This is a very straightforward process

    Create a form where the user enter's criteria for the search
    1) A textbox collects the search term
    2) Radio buttons or checkboxes will be used to indicate what fields the user is searching
    3) A button to tell the program to execute a search

    When the user clicks the button the code logic is as follows:
    1. Validate Entered Data (Check and make sure the search term is in the proper format for the database field you are searching on)
    2. Build a SQL statement based on the user entry
    (ex. Dim SQL as String = "SELECT * FROM TableName WHERE Field1 = '" & Textbox1.text & "'")
    3. Open a Connection to the Database
    4. Query for the data
    5. Parse the data and populate a datagrid with the results
    (step 5 might instead be binding the datagrid to the results instead of parsing the results)
    6. Close the connection to the database

    There are thousands of tutorials on connecting to databases with .net code... Here are some that will help you do build your search function: (connect to an access dB) (connect to a SQL Server Db) (excelent tutorial on connection to SQL Server DB and binding that data to a Datagrid)

    If you have code that won't work for you or need a specific command/function explained, I can help with that
Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!


In this Discussion