problem getting "LIKE @parameter%" to work

Posted on 2011-04-26
Medium Priority
Last Modified: 2012-06-21

   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 + "%')"
Question by:TonyReba
LVL 25

Expert Comment

by:Ron Malmstead
ID: 35468852
First, change your "+" symbols to "&" ampersand.

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

'%" + specialityDropDown.SelectedValue.ToString + " %'
To ....
'*" & specialityDropDown.SelectedValue.ToString & "*'
LVL 22

Expert Comment

by:Om Prakash
ID: 35468877
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

Author Comment

ID: 35468892
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

        End If

<asp:AccessDataSource ID="AccessDataSource1" runat="server" 
        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] = ? " >
            <asp:ControlParameter ControlID="providerTextBox" Name="newparameter" 
                PropertyName="Text" />
            <asp:ControlParameter ControlID="specialityDropDown" Name="newparameter" 
                PropertyName="SelectedValue" />

Open in new window

LVL 31

Accepted Solution

MlandaT earned 2000 total points
ID: 35978264
Try this in your declarations. I think you have syntax problems.
SelectCommand = "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 '%' + @Name + '%' OR Last_Name LIKE '%' + @Name + '%')"

    <asp:ControlParameter ControlID="providerTextBox" Name="Name" PropertyName="Text" />

Open in new window


Author Closing Comment

ID: 35999501
got it

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

MSSQL DB-maintenance also needs implementation of multiple activities. However, unprecedented errors can hamper the database management. In that case, deploying Stellar SQL Database Toolkit ensures fast and accurate database and backup repair as wel…
Beware when using the ListIndex and the Column() properties of a listbox in Access 2007.  A bug has been identified in the Access 2007 listbox code which can cause the .ListIndex property to return a -1, and the .Columns(#) property to return a NULL…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
The Relationships Diagram is a good way to get an overall view of what a database is keeping track of. It is also where relationships are defined. A relationship specifies how two tables connect to each other. As you build tables in Microsoft Ac…

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question