Connecting Tech Pros Worldwide Help | Site Map

Help with SELECT LIKE statement in Visual Web Developer

Newbie
 
Join Date: Nov 2006
Posts: 23
#1: Nov 21 '06
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:AccessDataSource ID="AccessDataSource1" 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!
msquared's Avatar
Administrator
 
Join Date: Aug 2006
Location: Dublin, Ireland
Posts: 10,865
#2: Nov 21 '06

re: Help with SELECT LIKE statement in Visual Web Developer


The wildcard in Access is '*' the asterisk.

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


Quote:

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:AccessDataSource ID="AccessDataSource1" 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!

Reply


Similar Microsoft Access / VBA bytes