Link to home
Start Free TrialLog in
Avatar of TonyReba
TonyRebaFlag for United States of America

asked on

search button asp.net

Why I cant get the results when I try to show restricted values (zip) (name)
Protected Sub searchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchButton.Click
        ListView1.DataBind()
        ListView1.Visible = "True"
        ListView2.Visible = "False"

        If specialityDropDown.SelectedValue = "All" And providerTextBox.Text = "" And txtZipCode.Text = "" Then

            ' Show All Results 
            ListView2.DataBind()
            ListView1.Visible = "False"
            ListView2.Visible = "True"
        End If

        If specialityDropDown.SelectedValue = "All" And (providerTextBox.Text <> "" Or txtZipCode.Text <> "") Then

            ' Show All Results 
            Dim sql As String
            'sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE ((@First_Name IS NULL OR First_Name LIKE '%' +  @First_Name + '%') OR (@Last_Name IS NULL OR Last_Name LIKE '%' +  @Last_Name + '%')) OR (@Zip IS NULL OR Zip LIKE '%' + @Zip + '%') "
            sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE Zip LIKE '%" + txtZipCode.Text + "%' "

            AccessDataSource2.SelectCommand = sql
            ListView1.Visible = "False"
            ListView2.Visible = "True"
            ListView1.DataBind()
        End If

    End Sub

    Protected Sub showallButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles showallButton.Click
        ' Show All Results 
        ListView2.DataBind()
        ListView1.Visible = "False"
        ListView2.Visible = "True"
    End Sub

Open in new window

SOLUTION
Avatar of Aksh
Aksh
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of TonyReba

ASKER

i believe thats not the issue but the logic  itself, I test Zip by itself but not with the other conditions
Avatar of puru1981
puru1981

what do you mean by restricted value???
I meant Where parameters sorry
this is my current code it filters by wharever I enter in the provider textbox, but not wherver I enter iun provider texbox and whatever I enter in the zip code texbox


If specialityDropDown.SelectedValue = "All" And (providerTextBox.Text <> "" Or txtZipCode.Text <> "") Then

            ' Show All Results 
            Dim sql As String
            sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE (   ((First_Name LIKE '%' +  providerTextBox.Text.ToString + '%') OR (Last_Name LIKE '%' +  providerTextBox.Text.ToString + '%')) OR ( ((First_Name LIKE '%' +  providerTextBox.Text.ToString + '%') OR (Last_Name LIKE '%' +  providerTextBox.Text.ToString + '%')) AND (Zip LIKE '%" + txtZipCode.Text.ToString + "%'   ))) "
            'sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE Zip LIKE '%" + txtZipCode.Text.ToString + "%'  "

            'sql = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax] FROM [tbl_Providers] WHERE ( (Zip LIKE '%" + txtZipCode.Text.ToString + "%') OR  (  (First_Name LIKE '%" + providerTextBox.Text.ToString + "%') OR (Last_Name LIKE '%" + providerTextBox.Text.ToString + "%') )"
            AccessDataSource3.SelectCommand = sql
            ListView1.Visible = False
            ListView2.Visible = True
            ListView2.DataBind()
        End If

Open in new window

ASKER CERTIFIED SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
That work for zip code it self , but It can be the case of having both the name and zipcode pertaining to that name
Nevermind I forgot to re-run, it worked
thanks guys