Hi all!

I'm trying to create search criteria for searching my sql server database. It selects the correct data when you select an option to search by; however i'm trying to make it so that if nothing is selected in an option it selects all data.

the code i'm using to achieve this is:

Dim itm As ListViewItem

        Dim varCommand As String

        varCommand = "SELECT tblBooking.BookingID, tblConcessions.ConcessionName, " & _
                "tblGardenCentre.GardenCentreName, tblBooking.StartDate," & _
                "tblBooking.EndDate " & _
                "FROM tblBooking " & _
                "INNER JOIN tblConcessions " & _
                "ON tblBooking.C_ID = tblConcessions.ConcessionID " & _
                "INNER JOIN tblGardenCentre " & _
                "ON tblBooking.GC_ID = tblGardenCentre.GardenCentreID " & _
                "WHERE "

        If Not txtBSBookingID.Text = Nothing Then
            varCommand = varCommand & "BookingID LIKE '" & If(txtBSBookingID.Text = "", "*", txtBSBookingID.Text) & "'"
        ElseIf cboInitials.SelectedIndex > -1 Or Not cboInitials.SelectedItem = "None" Then
            varCommand = varCommand & "FFInitiatedBy LIKE '" & If(cboInitials.SelectedItem = "None", "*", cboInitials.SelectedItem) & "'"

Can anyone see why my if statements withing the queries are not selecting all data (*).

Many Thanks for your time.

You should use % for a wildcard in queries, not * .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.