Zephaniah Chua
Zephaniah Chua

Reputation: 31

Visual Basic 2010 How to search database based on selection from 2 combobox

I am doing airline reservation system here I want to ask the user to choose the departure (combobox1) and destination (combobox2), and the system will read this 2 selection, the check with the database and show the available flight in the DataGridView.

The problem, how to set the search result will only show the flight that is based on combobox1 and combobox2?

This is the syntax I have made:

Private Sub btnSearch_Click(sender As System.Object, e As System.EventArgs) Handles btnSearch.Click

FlightDataGridView.DataSource = Me.FlightsDatabaseDataSet.Flight.Select("Departure= '" & ComboBox1.Text & "'")

FlightDataGridView.DataSource = Me.FlightsDatabaseDataSet.Flight.Select("Destination= '" & ComboBox2.Text & "'")

The result is:

As per the picture show, I want only the flight where the departure is Kuala Lumpur and Destination is Osaka, but it will show all the flight where destination is Osaka even the departure is not Kuala Lumpur.

Upvotes: 0

Views: 148

Answers (2)

Mukul Varshney
Mukul Varshney

Reputation: 3141

2nd statement for selecting the DataSource is updating the 1st statement. Combine the condition in one statement.

Upvotes: 0

Mike Lowery
Mike Lowery

Reputation: 2868

You need to use an SQL AND statement. Something like:

FlightDataGridView.DataSource = Me.FlightsDatabaseDataSet.Flight.Select("Departure= '" & ComboBox1.Text & "' AND Destination= '" & ComboBox2.Text & "'"")

Upvotes: 1

Related Questions