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

asked on

problem getting "LIKE @parameter%" to work

code:

   If specialityDropDown.SelectedValue <> "" Then
            ' Show me all doctors with that specialty
            Dim sql2 As String
            sql2 = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax], [Provider_Type] FROM [tbl_Providers] WHERE (Specialty LIKE '%" + specialityDropDown.SelectedValue.ToString + " %' OR Specialty2 LIKE '%" + specialityDropDown.SelectedValue.ToString + "%')"
Avatar of Ron Malmstead
Ron Malmstead
Flag of United States of America image

First, change your "+" symbols to "&" ampersand.

I also noticed a "space" ....and since this is MS Access syntax, not SQL...Wildcard should be * not %.

Example:
Change...
'%" + specialityDropDown.SelectedValue.ToString + " %'
To ....
'*" & specialityDropDown.SelectedValue.ToString & "*'
the query seems to be ok,
try printing the query and run it in the SQL management studio

also check the value in specialityDropDown.SelectedValue.ToString
Avatar of TonyReba

ASKER

I am not being able to get the parameters to pass into the ListView Control
    Protected Sub searchButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles searchButton.Click


        If specialityDropDown.SelectedValue = "All" And providerTextBox.Text <> "" Then
            ' Show me all doctors with that name
            Dim sql1 As String

            sql1 = "SELECT [First_Name],[Last_Name],[Prof_Designation], [Specialty], [Specialty2],[Address], [Address2], [City], [State], [Zip], [Phone], [Fax], [Provider_Type] FROM [tbl_Providers] WHERE (First_Name LIKE '%" + providerTextBox.Text.ToString + " %' OR Last_Name LIKE '%" + providerTextBox.Text.ToString + "%' ) "
            AccessDataSource1.SelectCommand = sql1
            ListView1.Visible = True
            ListView1.DataBind()

        End If


<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        DataFile="~/App_Data/Providers.mdb"  
        SelectCommand = " Select * From  [tbl_Providers] "     
        UpdateCommand="UPDATE [tbl_Providers] SET [Provider_Type] = ?, [Last_Name] = ?, [First_Name] = ?, [Prof_Designation] = ?, [Group_Business_Name] = ?, [Specialty] = ?, [Specialty2] = ?, [Address] = ?, [Address2] = ?, [City] = ?, [State] = ?, [Zip] = ?, [Phone] = ?, [Fax] = ? WHERE [ID] = ? " >
         
        <SelectParameters>
            <asp:ControlParameter ControlID="providerTextBox" Name="newparameter" 
                PropertyName="Text" />
            <asp:ControlParameter ControlID="specialityDropDown" Name="newparameter" 
                PropertyName="SelectedValue" />
        </SelectParameters>

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Mlanda T
Mlanda T
Flag of South Africa 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
got it