Database searching

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Boobbbbbb

    Database searching

    Hi all - total newbie to DB programming, so bear with me....

    I am using a Recordset object, and am trying to implement a search, but am
    not having luck finding what I need.

    I would like to enter a partial name, and seek records that contain that
    string, rather than equal it. All I can find for relational operators are
    =, <=, >=, >, and <.

    How would I go about doing a "contains" search?

    Thanks!


  • Slaatje

    #2
    Re: Database searching

    sql: like *blabla*

    Boobbbbbb heeft geschreven in bericht ...[color=blue]
    >Hi all - total newbie to DB programming, so bear with me....
    >
    >I am using a Recordset object, and am trying to implement a search, but am
    >not having luck finding what I need.
    >
    >I would like to enter a partial name, and seek records that contain that
    >string, rather than equal it. All I can find for relational operators are
    >=, <=, >=, >, and <.
    >
    >How would I go about doing a "contains" search?
    >
    >Thanks!
    >
    >[/color]


    Comment

    • Lee Johnson

      #3
      Re: Database searching

      "Boobbbbbb" wrote[color=blue]
      > OK... So I tried to use '*' as wildcards in this program line:
      > datNLA.Recordse t.Seek "=", "*Boo*"
      > and it does not work. :( Would I have to convert this to a SQL query?[/color]
      If[color=blue]
      > so, how? Again, I'm a total noob to doing this kind of thing in VB.[/color]

      Assuming you've dim your database and necessary variables used below, then:
      (replace the parts in <> with the appropriate info')

      Sub SearchDatabase( )
      'sub to search a database and assign the results to variables.

      'Make up the search term:
      strSQLString = "SELECT * FROM <table> WHERE <field> LIKE '<search term /
      variable>' "

      'Search the database with it:
      Set rs<yourRecordSe tQuery> = db<yourdatabase >.OpenRecords et (strSQLQuery,
      dbOpenForwardOn ly)

      'Assign appropriate variables using returned search results:
      While Not rs<yourRecordSe tQuery>.EOF

      arr<YourArray>[intCount] = rsQuery![<field>]
      intCount = intCount + 1

      rs<YourRecordSe tQuery>.MoveNex t

      Wend

      End Sub


      Comment

      • Jeff North

        #4
        Re: Database searching

        On Sat, 19 Jul 2003 14:39:49 GMT, in comp.lang.visua l.basic
        "Boobbbbbb" <armis2000SPAmM ENoT@earthlink. net> wrote:
        [color=blue]
        >| Hi all - total newbie to DB programming, so bear with me....
        >|
        >| I am using a Recordset object, and am trying to implement a search, but am
        >| not having luck finding what I need.
        >|
        >| I would like to enter a partial name, and seek records that contain that
        >| string, rather than equal it. All I can find for relational operators are
        >| =, <=, >=, >, and <.
        >|
        >| How would I go about doing a "contains" search?[/color]

        What database are you using?
        In Access you can use
        SELECT * FROM table WHERE fieldname like '*" & searchtext & "*'";

        If mySQL /SQL Server use:
        SELECT * FROM table WHERE fieldname like '%" & searchtext & "%'";

        ---------------------------------------------------------------
        jnorth@yourpant sbigpond.net.au : Remove your pants to reply
        ---------------------------------------------------------------

        Comment

        Working...