PDA

Click to See Complete Forum and Search --> : searhing a database


Nov 2nd, 2000, 05:34 AM
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!

jenlid
Nov 2nd, 2000, 07:34 AM
What do you want help with? Setting up the connection to the db, creating tables, writing vb-code?

kovan
Nov 2nd, 2000, 07:35 AM
you have to use ADO and sql



'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

jenlid
Nov 2nd, 2000, 07:49 AM
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 :-)

I´m not that sure how to use the '%'...

kovan
Nov 2nd, 2000, 07:51 AM
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

theroper
Nov 2nd, 2000, 10:18 AM
Remember LIKE is a lot slower than '='