Zephaniah Chua Zephaniah Chua - 1 month ago 7x
Vb.net Question

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


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.


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

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