Help with SELECT LIKE statement in Visual Web Developer

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gderosa
    New Member
    • Nov 2006
    • 23

    Help with SELECT LIKE statement in Visual Web Developer

    I am trying to perform a query on an Access database using Visual Web Developer based on a session variable. Here is the whole tag:

    <asp:AccessData Source ID="AccessDataS ource1" runat="server" DataFile="~/Residents.mdb"
    SelectCommand=" SELECT [last], [first], [unit], [urb] FROM [Residents] WHERE ([last] LIKE '%' + ? + '%')">

    Now I only want the results to start with lets say 'S' for Smith or Smitty. I understand that there should be no wildcard operator before the session variable ? above. But if I change the code it results nothing as the search, I have tried these variations with no success:
    WHERE ([last] LIKE '' + ? + '%')">
    WHERE ([last] LIKE ? + '%')">
    WHERE ([last] LIKE '?%')">

    Visual Web Developer automatically puts the ? in place of the session variable, which BTW is called Session("NAME")

    Can anyone please help with how to format the code so it would work? Thanks!
  • MMcCarthy
    Recognized Expert MVP
    • Aug 2006
    • 14387

    #2
    The wildcard in Access is '*' the asterisk.

    Access doesn't like to follow the pack. ;)


    Originally posted by gderosa
    I am trying to perform a query on an Access database using Visual Web Developer based on a session variable. Here is the whole tag:

    <asp:AccessData Source ID="AccessDataS ource1" runat="server" DataFile="~/Residents.mdb"
    SelectCommand=" SELECT [last], [first], [unit], [urb] FROM [Residents] WHERE ([last] LIKE '%' + ? + '%')">

    Now I only want the results to start with lets say 'S' for Smith or Smitty. I understand that there should be no wildcard operator before the session variable ? above. But if I change the code it results nothing as the search, I have tried these variations with no success:
    WHERE ([last] LIKE '' + ? + '%')">
    WHERE ([last] LIKE ? + '%')">
    WHERE ([last] LIKE '?%')">

    Visual Web Developer automatically puts the ? in place of the session variable, which BTW is called Session("NAME")

    Can anyone please help with how to format the code so it would work? Thanks!

    Comment

    Working...