473,396 Members | 2,093 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,396 software developers and data experts.

SQL works in Access but not ASP

Hi all,

Thanks again guys for the help re Select Case. I might trouble you with
something else:

I use this SQL in the Access query builder to return a single AirRate:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName = "Australia"
AND WeightCategory = "250"

Works fine but I've tried this in an ASP page:

rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""

But always get error messages such as the following:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/PPdemosite/shop_ccard_TEST.asp, line 214, column 82
rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName
= "Australia" AND WeightCategory = "250""
----------------------------------------------------------------------------
-----^
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
/PPdemosite/shop_ccard_TEST.asp, line 218

B.T.W, the connection and other properties are tested and okay.

Any ideas,

Regards

Penny.
Jul 22 '05 #1
4 1999
MDW
The problem is that in ASP, string variables are delimited by quotes. The
parameter values in your SQL statement are surrounded by quotes, and ASP is
getting confused. Try this:

1) In the SQL string, use single quotes instead of souble (that's what I
would do).
"Penny" wrote:

rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = 'Australia"'AND WeightCategory = '250'"

2) Also, I don't know if you typed it that way in your post, but ASP would
not tolerate a hard line break in the middle of your string (Access is OK
with line breaks in SQL statements - ASP is not that way). You do have
everything on one line in your app, yes?
Hi all,

Thanks again guys for the help re Select Case. I might trouble you with
something else:

I use this SQL in the Access query builder to return a single AirRate:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName = "Australia"
AND WeightCategory = "250"

Works fine but I've tried this in an ASP page:

rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""

But always get error messages such as the following:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/PPdemosite/shop_ccard_TEST.asp, line 214, column 82
rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName
= "Australia" AND WeightCategory = "250""
----------------------------------------------------------------------------
-----^
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
/PPdemosite/shop_ccard_TEST.asp, line 218

B.T.W, the connection and other properties are tested and okay.

Any ideas,

Regards

Penny.

Jul 22 '05 #2
you can also double quotes to obtain the same result. Sometimes you need to
triple quotes.
If you use an asp-capable editor (like dreamweaver or html-kit) you can see
in the code if you are doing it well or not.

Nick

"MDW" <MD*@discussions.microsoft.com> ha scritto nel messaggio
news:26**********************************@microsof t.com...
The problem is that in ASP, string variables are delimited by quotes. The
parameter values in your SQL statement are surrounded by quotes, and ASP
is
getting confused. Try this:

1) In the SQL string, use single quotes instead of souble (that's what I
would do).
"Penny" wrote:

rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = 'Australia"'AND WeightCategory = '250'"

2) Also, I don't know if you typed it that way in your post, but ASP would
not tolerate a hard line break in the middle of your string (Access is OK
with line breaks in SQL statements - ASP is not that way). You do have
everything on one line in your app, yes?
Hi all,

Thanks again guys for the help re Select Case. I might trouble you with
something else:

I use this SQL in the Access query builder to return a single AirRate:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName = "Australia"
AND WeightCategory = "250"

Works fine but I've tried this in an ASP page:

rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""

But always get error messages such as the following:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/PPdemosite/shop_ccard_TEST.asp, line 214, column 82
rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName
= "Australia" AND WeightCategory = "250""
----------------------------------------------------------------------------
-----^
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.
/PPdemosite/shop_ccard_TEST.asp, line 218

B.T.W, the connection and other properties are tested and okay.

Any ideas,

Regards

Penny.

Jul 22 '05 #3
Penny wrote:
Hi all,

Thanks again guys for the help re Select Case. I might trouble you
with something else:

I use this SQL in the Access query builder to return a single AirRate:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName =
"Australia" AND WeightCategory = "250"

Works fine but I've tried this in an ASP page:

rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""

But always get error messages such as the following:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/PPdemosite/shop_ccard_TEST.asp, line 214, column 82
rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""
Never set the source property directly like this. it makes debugging very
difficult. Always assign your strings to string variables and use the
variables where needed.
----------------------------------------------------------------------------
-----^
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 1. /PPdemosite/shop_ccard_TEST.asp, line 218


You must have changed the code to result in this message, right? You really
should have shown us what you changed it to.
The first error message has nothing to do with you connection, etc., which
you could determine by creating a simple test page with the following lines
of code:

<%
dim sSQL
sSQL = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""
Response.Write sSQL
%>

VBScript uses line breaks to determine where lines of code end. You have a
line break after the word "WHERE" so the compiler is expecting the line to
be finished at this point. So it parses the first line, which is:

sSQL = "SELECT AirRate FROM tblZoneShippingRates WHERE

The problem is, you used a delimiter (the quote) to begin the creation of a
string literal, but you never closed the string with a closing delimiter.
This forces an error to be raised.

So, let's fix that problem:
<%
dim sSQL
sSQL="SELECT AirRate FROM tblZoneShippingRates WHERE" & _
" ZoneName = "Australia" AND WeightCategory = "250""
Response.Write sSQL
%>
The underscore character (_) is called a "line continuation character". It
tells the compiler and parser that it should look at the following line to
get the rest of the statement. If this new code does not raise an error (it
should), look at the result of Response.Write after you run the page. Does
it look anything like the sql statement you were trying to create? I suspect
it will look like this:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName =

Can you figure out what is happening? Look at the statement from the
compiler's point of view:

sSQL is the name of a variable.
Since the statement did not start with "if" or some other keyword requiring
a comparison, = is an assignment operator; specifically, we are about to
assign a value to the sSQL variable.
The quote is a delimiter signalling te start of a string literal to be
assigned to the variable.
The next quote is another delimiter, signalling the end of the string
literal.
The & is the contatenation operator, signalling that more data is about to
be added to the string being created.
The _ says to look at the next line for the rest of the statement.
Another quote says to begin a new string literal (which will be added to the
string already in memory)
The next quote (after the = character ... before Australia) ends the string
literal - it delimits it.
The "A" character should raise an error, but if it doesn't, the rest of the
characters on this line will be ignored.

So, your problem is that you are attempting to use a character (the quote)
that is normally interpreted as a delimiter in your string and you want it
to be interpreted as a literal part of the string. Forcing a character that
normally has a function to be treated literally is called "escaping" the
character. The method for escaping a charater varies from language to
language. For example, in jscript, you would use a backslash (\) to escape a
character. In vbscript, you double up the character that needs to be
escaped. This technique is also used in most SQL language variants as well.

So, to force the quote to be treated literally, you escape it by doubling it
(""). So, option one is to do this:

<%
dim sSQL
sSQL="SELECT AirRate FROM tblZoneShippingRates WHERE" & _
" ZoneName = ""Australia"" AND WeightCategory = ""250"""
Response.Write sSQL
%>

Now, when you run this test page, you should see the result you expect.

Another option is to use apostrophes for your delimiters within the sql
statement:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName = 'Australia'
AND WeightCategory = '250'

will work as well as

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName = "Australia"
AND WeightCategory = "250"

Jet (Access) is unusual in that it allows quotes to be used for delimiters.
Most other sql variants only allow apostrophes to be used. So you will
probably be doing yourself a favor if you bite the bullet now and start
getting used to using apostrophes in your sql statements.

This will solve your immediate problem, but you will likely encounter more
problems. Read these posts for better alternatives to using dynamic sql:

Saved parameter queries (aka stored procedures or views):
http://groups-beta.google.com/group/...UTF-8&oe=UTF-8

http://groups-beta.google.com/group/...d322b882a604bd
Using Command object to parameterize CommandText:
http://groups-beta.google.com/group/...e36562fee7804e
HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Jul 22 '05 #4
Thanks for your tips fellas and your detailed directions Bob.

May take a while for me to digest it all!

Regards

Penny.
"Bob Barrows [MVP]" <re******@NOyahoo.SPAMcom> wrote in message
news:OO**************@TK2MSFTNGP09.phx.gbl...
Penny wrote:
Hi all,

Thanks again guys for the help re Select Case. I might trouble you
with something else:

I use this SQL in the Access query builder to return a single AirRate:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName =
"Australia" AND WeightCategory = "250"

Works fine but I've tried this in an ASP page:

rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""

But always get error messages such as the following:

Error Type:
Microsoft VBScript compilation (0x800A0401)
Expected end of statement
/PPdemosite/shop_ccard_TEST.asp, line 214, column 82
rsShipping.Source = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""
Never set the source property directly like this. it makes debugging very
difficult. Always assign your strings to string variables and use the
variables where needed.


--------------------------------------------------------------------------

--
-----^
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E10)
[Microsoft][ODBC Microsoft Access Driver] Too few parameters.
Expected 1. /PPdemosite/shop_ccard_TEST.asp, line 218


You must have changed the code to result in this message, right? You

really should have shown us what you changed it to.
The first error message has nothing to do with you connection, etc., which
you could determine by creating a simple test page with the following lines of code:

<%
dim sSQL
sSQL = "SELECT AirRate FROM tblZoneShippingRates WHERE
ZoneName = "Australia" AND WeightCategory = "250""
Response.Write sSQL
%>

VBScript uses line breaks to determine where lines of code end. You have a line break after the word "WHERE" so the compiler is expecting the line to
be finished at this point. So it parses the first line, which is:

sSQL = "SELECT AirRate FROM tblZoneShippingRates WHERE

The problem is, you used a delimiter (the quote) to begin the creation of a string literal, but you never closed the string with a closing delimiter.
This forces an error to be raised.

So, let's fix that problem:
<%
dim sSQL
sSQL="SELECT AirRate FROM tblZoneShippingRates WHERE" & _
" ZoneName = "Australia" AND WeightCategory = "250""
Response.Write sSQL
%>
The underscore character (_) is called a "line continuation character". It
tells the compiler and parser that it should look at the following line to
get the rest of the statement. If this new code does not raise an error (it should), look at the result of Response.Write after you run the page. Does
it look anything like the sql statement you were trying to create? I suspect it will look like this:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName =

Can you figure out what is happening? Look at the statement from the
compiler's point of view:

sSQL is the name of a variable.
Since the statement did not start with "if" or some other keyword requiring a comparison, = is an assignment operator; specifically, we are about to
assign a value to the sSQL variable.
The quote is a delimiter signalling te start of a string literal to be
assigned to the variable.
The next quote is another delimiter, signalling the end of the string
literal.
The & is the contatenation operator, signalling that more data is about to
be added to the string being created.
The _ says to look at the next line for the rest of the statement.
Another quote says to begin a new string literal (which will be added to the string already in memory)
The next quote (after the = character ... before Australia) ends the string literal - it delimits it.
The "A" character should raise an error, but if it doesn't, the rest of the characters on this line will be ignored.

So, your problem is that you are attempting to use a character (the quote)
that is normally interpreted as a delimiter in your string and you want it
to be interpreted as a literal part of the string. Forcing a character that normally has a function to be treated literally is called "escaping" the
character. The method for escaping a charater varies from language to
language. For example, in jscript, you would use a backslash (\) to escape a character. In vbscript, you double up the character that needs to be
escaped. This technique is also used in most SQL language variants as well.
So, to force the quote to be treated literally, you escape it by doubling it (""). So, option one is to do this:

<%
dim sSQL
sSQL="SELECT AirRate FROM tblZoneShippingRates WHERE" & _
" ZoneName = ""Australia"" AND WeightCategory = ""250"""
Response.Write sSQL
%>

Now, when you run this test page, you should see the result you expect.

Another option is to use apostrophes for your delimiters within the sql
statement:

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName = 'Australia'
AND WeightCategory = '250'

will work as well as

SELECT AirRate FROM tblZoneShippingRates WHERE ZoneName = "Australia"
AND WeightCategory = "250"

Jet (Access) is unusual in that it allows quotes to be used for delimiters. Most other sql variants only allow apostrophes to be used. So you will
probably be doing yourself a favor if you bite the bullet now and start
getting used to using apostrophes in your sql statements.

This will solve your immediate problem, but you will likely encounter more
problems. Read these posts for better alternatives to using dynamic sql:

Saved parameter queries (aka stored procedures or views):
http://groups-beta.google.com/group/...r.asp.general/
msg/713f592513bf333c?hl=en&lr=&ie=UTF-8&oe=UTF-8
http://groups-beta.google.com/group/...r.asp.db/msg/b
3d322b882a604bd

Using Command object to parameterize CommandText:
http://groups-beta.google.com/group/...r.asp.db/msg/7
2e36562fee7804e

HTH,
Bob Barrows

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"

Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Dan Nash | last post by:
Hi guys I have a page that is *supposed* to list the directories on the server. Here's the code... folderspec = server.MapPath("./images/") set fso =...
1
by: Moi | last post by:
I have tried repeatedly to import a MS Works database (simple address database) into Access, but I am having little luck. I have saved the Works file as DbaseIII DbaseIV and neither is seen by the...
0
by: Miguelito Bain | last post by:
hi everybody- i've got a conundrum... i inherited some old databases, and i'm trying to convert them. i run office xp with access 2002, and all of the databases i manage are either in 97...
1
by: Clifton | last post by:
I included Access in my new computer especially to be able to receive Access database files, edit and send back. A) Can I do that? B)Where do I copy the received(Email) file; a new folder created...
3
by: Tlaker | last post by:
MS Works 6.0 to Access 2000. Tried saving to *.csv and dbf as well as converting to Excel then loading but to no avail. My Works database has about 4000 records, each with about 30 fields. Is...
10
by: skiz | last post by:
I have an application written in ms access 97. Just recently certain queries have been giving various errors -- one of which is "there was an error executing the command". When I ran the...
2
by: chiefsitebuilder | last post by:
I have a question about saving an MS Access program to CD and verifyng that the program works after being saved. Here is my situation, I have a person who developed an application for me using...
8
by: Michael B. Trausch | last post by:
I was wondering if anyone has had any experience with this. Someone I know is trying to move away from Microsoft Works, and I am trying to look into a solution that would convert their data in a...
2
by: Cindy | last post by:
I have an Access 2003 database with a query that works fine on my PC but does not work on another PC. My PC has older versions of Access installed as well as 2003 - the other PC only has Access...
11
by: John | last post by:
Access 2003 After my app is finished I'd like to create an mde file. Therefore my db has to be made in the 2002-2003 format. So I've created a new mdb (default in 2000 format), I converted this...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

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.