473,671 Members | 2,271 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 tblZoneShipping Rates WHERE ZoneName = "Australia"
AND WeightCategory = "250"

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

rsShipping.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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 2008
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.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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 tblZoneShipping Rates WHERE ZoneName = "Australia"
AND WeightCategory = "250"

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

rsShipping.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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*@discussion s.microsoft.com > ha scritto nel messaggio
news:26******** *************** ***********@mic rosoft.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.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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 tblZoneShipping Rates WHERE ZoneName = "Australia"
AND WeightCategory = "250"

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

rsShipping.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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 tblZoneShipping Rates WHERE ZoneName =
"Australia" AND WeightCategory = "250"

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

rsShipping.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates WHERE ZoneName = 'Australia'
AND WeightCategory = '250'

will work as well as

SELECT AirRate FROM tblZoneShipping Rates 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******@NOyah oo.SPAMcom> wrote in message
news:OO******** ******@TK2MSFTN GP09.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 tblZoneShipping Rates WHERE ZoneName =
"Australia" AND WeightCategory = "250"

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

rsShipping.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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.Sour ce = "SELECT AirRate FROM tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates 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 tblZoneShipping Rates WHERE ZoneName = 'Australia'
AND WeightCategory = '250'

will work as well as

SELECT AirRate FROM tblZoneShipping Rates 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/713f592513bf333 c?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
2469
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 = CreateObject("Scripting.FileSystemObject") set fold = fso.GetFolder(folderspec) for each subfolder in fold.subFolders Response.Write(subfolder.name & "<br>")
1
3111
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 Access importer. Does anyone have any advice or a link that might help me through this. Much thanks in advance.
0
1404
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 format or 2000 format. i have a list box that works in access 97 but not 2000. here's my situation...
1
1367
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 for that purpose, or? C) If I have or receive a works database file, can I convert to an Access file? and D)Do I need Works installed on the new computer?
3
1598
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 there a way to convert to Access without re-entering the information 1 record at a time? TIA
10
1792
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 application in access 2000, no errors occurred. Any ideas? If I open the database file in 2000 it asks me if I want to convert the database -- so, I know that it is still a 97 database. Thanks! skiz
2
1838
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 MS Access 2003 and the person will be transferring ownership to me. The developer will be giving me a CD with Access DBase source code on it. How do I verify that he gives me everthing I need to run the application once the developer departs. ...
8
2230
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 lossless fashion to a more modern format. The database has more than 65K rows, so converting it to be an Excel spreadsheet, would, AFAIK, not be an option. It would seem that MS Works can export the database as a DBF format database, though I...
2
2701
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 2003. The query is as follows: SELECT tblOrganization.strOrgName, tblPerson.strNameL, tblPerson.strNameF, tblPersonFCL_Courses.lngIDPerson, tblPersonFCL_Courses.strHOTest, tblPersonFCL_Courses.strCert, tblPersonFCL_Courses.ysnProcessed,...
11
1889
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 empty mdb to the 2002-2003 format. I've started to add code but discovered that non of my VB code works. Even a simple <<msgbox "test">doesn't work. I constantly get the message about miscommunication between Access and OLE souce program or Active...
0
8473
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8911
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8819
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8597
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8667
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7428
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
4402
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2808
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
1806
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.