Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > SQL Statement Error?!

Reply
Thread Tools

SQL Statement Error?!

 
 
Oli
Guest
Posts: n/a
 
      12-03-2003
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


 
Reply With Quote
 
 
 
 
Ray at
Guest
Posts: n/a
 
      12-03-2003
sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company")

RESPONSE.WRITE SQL
RESPONSE.END

What does that show you?

Ray at work


"Oli" <(E-Mail Removed)> wrote in message
news:bqks2u$e7k$(E-Mail Removed)...
> 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
>
>



 
Reply With Quote
 
 
 
 
Oli
Guest
Posts: n/a
 
      12-03-2003
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 <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:(E-Mail Removed)...
> sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company")
>
> RESPONSE.WRITE SQL
> RESPONSE.END
>
> What does that show you?
>
> Ray at work
>
>
> "Oli" <(E-Mail Removed)> wrote in message
> news:bqks2u$e7k$(E-Mail Removed)...
> > 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
> >
> >

>
>



 
Reply With Quote
 
Mike D
Guest
Posts: n/a
 
      12-03-2003
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" <(E-Mail Removed)> wrote in message
news:bqksvp$hss$(E-Mail Removed)...
> 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 <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
> news:(E-Mail Removed)...
> > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company")
> >
> > RESPONSE.WRITE SQL
> > RESPONSE.END
> >
> > What does that show you?
> >
> > Ray at work
> >
> >
> > "Oli" <(E-Mail Removed)> wrote in message
> > news:bqks2u$e7k$(E-Mail Removed)...
> > > 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
> > >
> > >

> >
> >

>
>



 
Reply With Quote
 
Bob Barrows
Guest
Posts: n/a
 
      12-03-2003
Oli wrote:
> 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

--
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.


 
Reply With Quote
 
Oli
Guest
Posts: n/a
 
      12-03-2003
Thanks Guys!


"Bob Barrows" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Oli wrote:
> > 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
>
> --
> 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.
>
>



 
Reply With Quote
 
Bhaskardeep Khaund
Guest
Posts: n/a
 
      12-03-2003
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
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
SQL Reference, SQL Queries, SQL help ecoolone ASP .Net 0 01-03-2008 10:58 AM
asp and sql statement in sql server db weiwei ASP General 3 09-22-2004 04:12 PM
DBI SQL column datatype not jiving with SQL statement requirement dna Perl 1 01-18-2004 04:15 PM
Re: SQL statement working in SQL Server but not in .aspx.cs page David Browne ASP .Net 0 08-21-2003 10:43 PM
Re: SQL statement working in SQL Server but not in .aspx.cs page William \(Bill\) Vaughn ASP .Net 0 08-21-2003 10:41 PM



Advertisments