SQL Statement Error?!

O

Oli

Hi,

Im trying to use a sesson statement within an SQL Statement:

sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company") &
""

And get the error:

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

Anyone got any ideas? Surely this can only be something basic?

TIA
Oli
 
R

Ray at

sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company")

RESPONSE.WRITE SQL
RESPONSE.END

What does that show you?

Ray at work
 
O

Oli

SELECT * FROM tblNumbers WHERE AllocatedTo=AlternateMedia

Which is correct! Just noticed that the error is not with that line....
Line 33 is:

rs.Open sql, cn

What does "Expected 1" mean?

Thanks!
Oli



Ray at said:
sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company")

RESPONSE.WRITE SQL
RESPONSE.END

What does that show you?

Ray at work


Oli said:
Hi,

Im trying to use a sesson statement within an SQL Statement:

sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company") &
""

And get the error:

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

Anyone got any ideas? Surely this can only be something basic?

TIA
Oli
 
M

Mike D

This SELECT * FROM tblNumbers WHERE AllocatedTo=AlternateMedia isn't correct
it should be
SELECT * FROM tblNumbers WHERE AllocatedTo='AlternateMedia'

And don't use select * in production code

Mike

Oli said:
SELECT * FROM tblNumbers WHERE AllocatedTo=AlternateMedia

Which is correct! Just noticed that the error is not with that line....
Line 33 is:

rs.Open sql, cn

What does "Expected 1" mean?

Thanks!
Oli



Ray at said:
sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company")

RESPONSE.WRITE SQL
RESPONSE.END

What does that show you?

Ray at work
Session("Company")
&
""

And get the error:

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

Anyone got any ideas? Surely this can only be something basic?

TIA
Oli
 
B

Bob Barrows

Oli said:
SELECT * FROM tblNumbers WHERE AllocatedTo=AlternateMedia

Which is correct!

No, it is not correct. Strings need to be delimited in queries.This is
correct:
SELECT * FROM tblNumbers WHERE AllocatedTo='AlternateMedia'
Just noticed that the error is not with that
line.... Line 33 is:

rs.Open sql, cn

What does "Expected 1" mean?

That's not the whole error message. The whole message is "Too few
parameters. Expected 1."

Because you did not delimit the word AlternateMedia, Jet looked for a field
named AlternateMedia in your table. When it did not find one, it treated
AlternateMedia as a parameter. Since you did not provide a value for the
parameter, it returned the error you reported. It's "expecting" a value for
"1" parameter.

If you had copied and pasted that query from the browser window into the SQL
View of the Access Query Builder and tried to run it, you would have been
prompted for a value for AlternateMedia. (this is how you should debug your
queries)

Your code should be changed to:

sql = "SELECT * FROM tblNumbers WHERE AllocatedTo='" & _
Session("Company") & "'"


Better yet, instead of using dynamic sql, you should use a saved parameter
query. A Google search should find plenty oif examples of this.

HTH,
Bob Barrows
 
O

Oli

Thanks Guys!


Bob Barrows said:
No, it is not correct. Strings need to be delimited in queries.This is
correct:
SELECT * FROM tblNumbers WHERE AllocatedTo='AlternateMedia'


That's not the whole error message. The whole message is "Too few
parameters. Expected 1."

Because you did not delimit the word AlternateMedia, Jet looked for a field
named AlternateMedia in your table. When it did not find one, it treated
AlternateMedia as a parameter. Since you did not provide a value for the
parameter, it returned the error you reported. It's "expecting" a value for
"1" parameter.

If you had copied and pasted that query from the browser window into the SQL
View of the Access Query Builder and tried to run it, you would have been
prompted for a value for AlternateMedia. (this is how you should debug your
queries)

Your code should be changed to:

sql = "SELECT * FROM tblNumbers WHERE AllocatedTo='" & _
Session("Company") & "'"


Better yet, instead of using dynamic sql, you should use a saved parameter
query. A Google search should find plenty oif examples of this.

HTH,
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.
 
B

Bhaskardeep Khaund

Hi,

Change your SQL statement to this:-
sql = "SELECT * FROM tblNumbers WHERE AllocatedTo='" & Session("Company") &"'"

Because, tour AllocatedTo field must be a VarChar or Char data field. But you wnat to enter a Numeric data into it.

Hope this helps.

Bhaskardeep Khaund
 

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

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top