Results 1 to 6 of 6

Thread: searhing a database

  1. #1
    Guest

    Question

    Can anyone help me with making a search function?
    I'm using a Access 2000 db with vb6.
    My Project is: I'm gonna make a program for a video-rental-store, with posibility to search on customers name and Movie-title. Is this any help for you? Hopeing for an answer!

  2. #2
    New Member
    Join Date
    Oct 2000
    Location
    Swe
    Posts
    14

    Question

    What do you want help with? Setting up the connection to the db, creating tables, writing vb-code?
    Jesse

  3. #3
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    you have to use ADO and sql


    Code:
    'assuming your ado recordset is called RS and connection is called conn
    
    dim SQLStatement as string
    
    If SearchByCustomer = True then
       dim CustomerName as string
       CustomerName = txtcustomer.text
       SQLStatement = "SELECT * FROM MyTable WHERE CustomerName = '" & CustomerName & "'"
    elseif SearchByTitle then
       Dim VideoTitle as string
       VideoTitle = txtvideotitle.text
       SQLStatement = "SELECT * FROM MyTable WHERE VideoTitle = '" & VideoTitle & "'"
    end if
    
    RS.Open SQLStatement, conn
    with rs
       if .eof then
          msgbox "nothing found"
       else
           'do what ever you want with whts found
       end if
       .close
    end with
    i hope that helped
    if you need more help let me know



  4. #4
    New Member
    Join Date
    Oct 2000
    Location
    Swe
    Posts
    14
    Use LIKE instead:

    SELECT * FROM MyTable WHERE CustomerName LIKE '"%" & CustomerName & "%"'"

    If you typed in "Ander" the statement will find every customer which name contains Ander, for example Andersson, Anderlecht and so on :-)

    Im not that sure how to use the '%'...
    Jesse

  5. #5
    Frenzied Member
    Join Date
    Aug 2000
    Posts
    1,539
    assumption was based on he wanted to check for exact

    you use % by typing it at the beganning and end of the string

    like this

    videotitle LIKE '%kova%'
    have fun sqling

  6. #6
    New Member
    Join Date
    Aug 2000
    Posts
    15
    Remember LIKE is a lot slower than '='

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