Too few parameters. Expected 1.

D

DVan

I have read what this error means, you have invalid column names from the
select statement, misspelling etc.

Here is an excerpt from both my pages, not sure why I am getting this error
still.

----------------------------------------------------------------------------
-
strsql = "select * from Printers where PrinterName <> 'N/A'"

Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtest=dsntest & "DBQ=" & Server.MapPath("/database/sa inventory.mdb")
Conn.Open DSNtest

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn, 3,3

----------------------------------------------------------------------------
-
I then send this data to the npResults2 page

response.write "<TD BORDER=1 ALIGN=CENTER WIDTH=50>" & vbcrlf
response.write "<A target='myNewWin' HREF='npResults2.asp?pn=" &
rs("PrinterName")& "'>Edit</a>"
response.write "</TD>" & vbcrlf
----------------------------------------------------------------------------
-

iSerial = Request.QueryString("pn")

strSQL = "SELECT * FROM printers WHERE PrinterName=" & iSerial & ";"

Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtest=dsntest & "DBQ=" & Server.MapPath("/database/sa inventory.mdb")
Conn.Open DSNtest

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn, 3,3


Any help is much appreciated.
 
B

Bob Barrows [MVP]

DVan said:
I have read what this error means, you have invalid column names from
the select statement, misspelling etc.

Here is an excerpt from both my pages, not sure why I am getting this
error still.

-------------------------------------------------------------------------- --
-
strsql = "select * from Printers where PrinterName <> 'N/A'"

Does this sql statement run without error when you test it using the Access
Query Builder?
Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={Microsoft Access Driver (*.mdb)}; "
http://www.aspfaq.com/show.asp?id=2126

DSNtest=dsntest & "DBQ=" & Server.MapPath("/database/sa
inventory.mdb")

Does

Response.Write Server.MapPath("/database/sa inventory.mdb")

display the correct path to your database?

Bob Barrows
 
D

DVan

Yes to both questions, I have the same script that works on another page.
I can't figure it out.
 
R

Ray Costanzo [MVP]

Is PrinterName a text-based column type? If so, you need to delimit the
data with ' characters.

Function sIn(s)
sIn = "'" & Replace(s, "'", "''") & "'"
End Function

sSQL = "SELECT * FROM Printers WHERE PrinterName = sIn(iSerial)

Ray at work
 
D

DVan

Hi Ray,

I added this to my webpage

<SCRIPT LANGUAGE="JavaScript">
Function sIn(s)
sIn = "'" & Replace(s, "'", "''") & "'"
End Function
</SCRIPT>


Then changed the strSQL to

strSQL = "SELECT * FROM Printers WHERE PrinterName = sIn(iSerial)"


and it is still giving me the same error on this line

rs.Open strsql, conn, 3,3
 
B

Bob Barrows [MVP]

I did not realize you had two sql statements. Which one is raising the
error? The one where you concatenate the iSerial value in? If so, see below:
I have read what this error means, you have invalid column names from
the select statement, misspelling etc.

Here is an excerpt from both my pages, not sure why I am getting this
error still.

-------------------------------------------------------------------------- --
-
strsql = "select * from Printers where PrinterName <> 'N/A'"

Set Conn = Server.CreateObject("ADODB.Connection")
DSNtest="DRIVER={Microsoft Access Driver (*.mdb)}; "
DSNtest=dsntest & "DBQ=" & Server.MapPath("/database/sa
inventory.mdb") Conn.Open DSNtest

Set rs = Server.CreateObject("ADODB.Recordset")
rs.Open strsql, conn, 3,3

Does this line raise an error?

-------------------------------------------------------------------------- --
-
I then send this data to the npResults2 page

response.write "<TD BORDER=1 ALIGN=CENTER WIDTH=50>" & vbcrlf
response.write "<A target='myNewWin' HREF='npResults2.asp?pn=" &
rs("PrinterName")& "'>Edit</a>"
response.write "</TD>" & vbcrlf
-------------------------------------------------------------------------- --
-

iSerial = Request.QueryString("pn")

strSQL = "SELECT * FROM printers WHERE PrinterName=" & iSerial & ";"

Do

Response.Write strSQL

Try to run the sql statement that appears in the browser window using the
Access Query Builder. I think you'll see what the error is, especially if
you compare it to the earlier sql statement that works.

Here is some advice that will help you avoid this error in the future:
http://www.google.com/groups?hl=en&lr=&ie=UTF-8&oe=UTF-8&[email protected]

http://www.google.com/groups?hl=en&...x.gbl&rnum=11&prev=/groups?q=delimiter+author
:Bob%2Bauthor:Barrows%26hl%3Den%26lr%3D%26ie%3DUTF-8%26oe%3DUTF-8%26start%3D
10%26sa%3DN

Bob Barrows
 
D

DVan

Yes, that one.

I added this per Ray, but still the same problem

I added this to my webpage

<SCRIPT LANGUAGE="JavaScript">
Function sIn(s)
sIn = "'" & Replace(s, "'", "''") & "'"
End Function
</SCRIPT>


Then changed the strSQL to

strSQL = "SELECT * FROM Printers WHERE PrinterName = sIn(iSerial)"


and it is still giving me the same error on this line

rs.Open strsql, conn, 3,3
 
B

Bob Barrows [MVP]

DVan said:
Yes, that one.

I added this per Ray, but still the same problem

I added this to my webpage

<SCRIPT LANGUAGE="JavaScript">
Function sIn(s)
sIn = "'" & Replace(s, "'", "''") & "'"
End Function
</SCRIPT>


Then changed the strSQL to

strSQL = "SELECT * FROM Printers WHERE PrinterName = sIn(iSerial)"
I repeat: Response.Write it and attempt to run the resulting statement from
the browser window in Access.

You'll see the problem (I hope). You cannot debug a sql statement without
knowing what it is. Knowing what the vbscript code that's supposed to
generate it looks like will not help. You need to look at the resulting
statement.


Hint: Does your Printers table contain a field called "sIn(iSerial)"?

Please consider using saved parameter queries as explained in the links in
my previous message.

Bob Barrows
 
D

DVan

OK. Thanks, I will give it a try.

Bob Barrows said:
I repeat: Response.Write it and attempt to run the resulting statement from
the browser window in Access.

You'll see the problem (I hope). You cannot debug a sql statement without
knowing what it is. Knowing what the vbscript code that's supposed to
generate it looks like will not help. You need to look at the resulting
statement.


Hint: Does your Printers table contain a field called "sIn(iSerial)"?

Please consider using saved parameter queries as explained in the links in
my previous message.

Bob Barrows
--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.
 
A

Aaron [SQL Server MVP]

Your function is in client side code. And you STILL haven't delimited the
printername correctly. The SQL statement is looking for exactly what you
typed, a printername value of "sln(iSerial)" without the quotes ...

Have you tried Response.Write strSQL as others have suggested, instead of
just scratching your head over the error?

<%
' ... populate iSerial up here, I assume, from who knows what ...

function sln(s)
sln = "'" & replace(s, "'", "''") & "'"
end function

strSQL = "SELECT * FROM Printers WHERE PrinterName = " & sln(iSerial)
response.write strSQL
response.end
%>

And name your columns, instead of using SELECT *.

--
http://www.aspfaq.com/
(Reverse address to reply.)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,731
Messages
2,569,432
Members
44,832
Latest member
GlennSmall

Latest Threads

Top