Results 1 to 4 of 4

Thread: Search Database

  1. #1

    Thread Starter
    Member
    Join Date
    Jan 2013
    Posts
    62

    Search Database

    Hi,

    I need to find a way to search my database - however, I haven't ever made a search before and only have an idea of what (I think) I need to do?

    It'd be great if someone could help me out or get me started along the right lines?

    I'm thinking I need to do something like this?

    1. User enters search criteria (e.g. into a text box or input box)
    2. Code takes users entry and puts it into a variable RecipeSearchText
    3. SQL goes to the database and looks for all matches – puts them into the dataset
    4. Combobox then filled with all matches as the display member, and the recipeID as value member.

    Yet I still have NO IDEA where to start coding with this haha!

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,302

    Re: Search Database

    I would suggest that you follow the Database FAQ and/or Data Walkthroughs links in my signature below to learn something about data access.

  3. #3
    Smooth Moperator techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,532

    Re: Search Database

    I haven't ever made a search before
    To be honest... that's not true... I was just in your other thread... you do know how to do a search... you just may not realize it.
    It's all in the where clause... even something like this:
    Code:
    WHERE ID = 3
    Is a search... it's searching for the record where the ID is 3.

    So what you need is to search for all records where a field is LIKE the value in RecipeSearchText...

    Code:
    WHERE yourRecipieField like '%' + " & RecipeSearchText & " + '%'"
    just because JM slapped my hand a moment ago for using concatenation, here's the parameterized version

    Code:
    WHERE yourRecipieField like '%' + @SearchText + '%'"
    Then you can use .AddWithValue to add RecipeSearchText to the parameters collection.

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  4. #4

    Thread Starter
    Member
    Join Date
    Jan 2013
    Posts
    62

    Re: Search Database

    Yeah when I posted it... didn't have a scooby haha!

    Cheers TJ, you've been a big help with this

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width