?
Solved

problem getting "LIKE @parameter%" to work

Posted on 2011-04-26
5
Medium Priority
?
255 Views
Last Modified: 2012-06-21
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 + "%')"
0
Comment
Question by:TonyReba
5 Comments
 
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 %.

Example:
Change...
'%" + specialityDropDown.SelectedValue.ToString + " %'
To ....
'*" & specialityDropDown.SelectedValue.ToString & "*'
0
 
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
0
 
LVL 9

Author Comment

by:TonyReba
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
            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

0
 
LVL 31

Accepted Solution

by:
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 + '%')"

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

Open in new window

0
 
LVL 9

Author Closing Comment

by:TonyReba
ID: 35999501
got it
0

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