How can I search a database on multiple criteria selected from listboxes?

I am new to VB and I am finding it difficult to understand. I am using Visual Studio 2005.

I want to search a database for several items, I am using the My Movie Collection template to practice with and I want to be able to search for actors, directors and release dates and see the movies that match.

I want to use listboxes for the items to search on and populate them with the possible options from the database. Ideally I would like the results to be updated as I click on the options in the listboxes (no 'search' button). I want to be able to click on more than one item in a listbox (e.g. several dates) and I want to be able to deselect items that I previously clicked on.

I have found examples of searching for one thing in a database but I cannot find any examples of how to search for multiple items or how to use listboxes to do the search. I have spent ages looking for a solution and I am getting really confused about what I need to do.

L.

[987 byte] By [L123] at [2007-12-22]
# 1

Are you building an SQL to do the search?

Something like

SELECT fields FROM table WHERE actor_name = 'Clint Eastwood'

Assuming you are, you may need to brush up on you SQL

For exmple you can search for multiple actors using the IN clause

SELECT fields FROM table WHERE actor_name IN ('Clint Eastwood','Jan Hyde')

Syntax may vary depending on what database your using.

If you wanted to reduce the list further, to a specific director

SELECT fields FROM table

WHERE actor_name IN ('Clint Eastwood','Jan Hyde')

AND director_name = 'Fred Flintstone'

Before I go any further is this any help at all?

JanHyde at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 2

Jan,

That looks like what I want to do but everytime I tried to use SQL I seem to make the application hang up. Also I couldn't work out where to put the SQL either so I though I maybe had to write VB code instead.

L.

L123 at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 3

Depending on the size of your table, indexes etc, perfomance of the SQL may well be a problem.

Why not show us what you tried and tell us what the problem was with it and we'll try and help you fix it.

JanHyde at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...
# 4

I haven't got very far as I keep running into problems. I just went back to the begining and tried just adding a listbox for director but as soon as I put in the databinding when I add new items to the database they don't get saved. I just set the data source to DVDsBindingSource and the display value to Director.

L123 at 2007-8-30 > top of Msdn Tech,Visual Basic,Visual Basic General...