473,320 Members | 2,112 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Help with SELECT LIKE statement in Visual Web Developer

23
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!
Nov 21 '06 #1
8 2466
AricC
1,892 Expert 1GB
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE last LIKE '%S%'
Nov 21 '06 #2
gderosa
23
Try this:

Expand|Select|Wrap|Line Numbers
  1.  
  2. WHERE last LIKE '%S%'
I didnt want the query to return just results that start with S, I want it to return results that start with the session parameter, Session("NAME"), I was just using the S as an example.
Nov 21 '06 #3
AricC
1,892 Expert 1GB
Try and hard code it with that to see if it works then worry about adding the session name.
Nov 22 '06 #4
gderosa
23
Yup it works by hardcoding it like that but it brings me all results that have 's' in them wheras I want all results that start with 's' as an example. If all worked correctly I would like the results to start with the stored session variable, which it is not doing. It is returning results that include the session variable but not the ones that start with the session variable. I really appreciate ur help!

For example I currently have it like this:
WHERE ([last] LIKE '%' + ? + '%')">
Which is returning results that include the session variable, but I want to return results that start with the session variable and have tried all these variations below but none of them work:
WHERE ([last] LIKE '' + ? + '%')">
WHERE ([last] LIKE ? + '%')">
WHERE ([last] LIKE '?%')">
Nov 22 '06 #5
iam_clint
1,208 Expert 1GB
replace + with &
Nov 22 '06 #6
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!
What about

WHERE ([last] LIKE "& &")

If its text leteral (sp) add the ' ' around it.
or if it suppose to be text it would be WHERE ([last} LIKE '"& ? &"')

If the ? is a varaible it could be name or some other naming convention. Let me know if it works.
Nov 22 '06 #7
gderosa
23
What about

WHERE ([last] LIKE "& &")

If its text leteral (sp) add the ' ' around it.
or if it suppose to be text it would be WHERE ([last} LIKE '"& ? &"')

If the ? is a varaible it could be name or some other naming convention. Let me know if it works.
I tried the LIKE '"& ? & "' and it still doesnt work, it says poorly formed expression. Thanks for your help though!
Nov 24 '06 #8
gderosa
23
I tried the LIKE '"& ? & "' and it still doesnt work, it says poorly formed expression. Thanks for your help though!
wow I cant believe I got it to work all it needed was a space in place of the first %:

WHERE ([last] LIKE ' ' + ? + '%')
Nov 24 '06 #9

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: SD | last post by:
Hi, I'm running Windows XP and SQL Server Developer Edition (sp3) and I'm trying to install the MS SQL Server Reporting Services that is in the MSDN of April 2004. I also have Visual studio.net...
4
by: Terencetrent | last post by:
I having been using Access '97/2002 for about 4 years now and have never really had the need or the time to learn visual basic. Well, I think the time has finally come. I need help with Visual...
3
by: ssb | last post by:
Hello, This may be very elementary, but, need help because I am new to access programming. (1) Say, I have a column EMPLOYEE_NAME. How do I fetch (maybe, cursor ?) the values one by one and...
5
by: freddy | last post by:
I have a select statement like this: string Select = "Select TableofContents, DataOwner, Delegates From NYC"; and it work fine, but if I was to put a space in like this: string Select = "Select...
2
by: tjones | last post by:
Hi, I have installed VS2003 and have been wroting some c++ code. Mainly created a win32 console application for my c++ program. I have a few questions: 1. Is there a menu to...
2
by: NathanV | last post by:
I need some help with a SQL statement (SQL Server 2k). I have three tables, an Artists table which holds user info, a Types table which holds the TypeID and Description for different types (I.e....
4
by: | last post by:
Environment: Microsoft Visual Studio 2005 Professional Edition Microsoft Visual Source Safe 2005 FxCop 1.32 Project: ASP.NET 2.0 C# Project 5 Developers We are trying to implement FxCop...
5
by: chris.withers | last post by:
Hi all, I'm attempting to do something like the following SQL query: SELECT * FROM `users` WHERE idusers != 3 | 2; such as: = "idusers <> 3OR 2";
1
by: gderosa | last post by:
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"...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.