Database Search - Programmers Heaven

Howdy, Stranger!

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

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Database Search

Inspire_shinInspire_shin Posts: 10Member
Hi,

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.

Comments

  • seancampbellseancampbell Pennsylvania, USAPosts: 684Member ✭✭✭
    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:

    http://www.homeandlearn.co.uk/NET/nets12p4.html (connect to an access dB)
    http://www.startvbdotnet.com/ado/sqlserver.aspx (connect to a SQL Server Db)
    http://aspnet.4guysfromrolla.com/articles/040502-1.aspx (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
    Firesickle.com
Sign In or Register to comment.