SQL Statement Error?!

Discussion in 'ASP General' started by Oli, Dec 3, 2003.

  1. Oli

    Oli Guest

    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
    Oli, Dec 3, 2003
    #1
    1. Advertising

  2. Oli

    Ray at Guest

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

    RESPONSE.WRITE SQL
    RESPONSE.END

    What does that show you?

    Ray at work


    "Oli" <> wrote in message
    news:bqks2u$e7k$...
    > 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
    >
    >
    Ray at, Dec 3, 2003
    #2
    1. Advertising

  3. Oli

    Oli Guest

    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:...
    > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company")
    >
    > RESPONSE.WRITE SQL
    > RESPONSE.END
    >
    > What does that show you?
    >
    > Ray at work
    >
    >
    > "Oli" <> wrote in message
    > news:bqks2u$e7k$...
    > > 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
    > >
    > >

    >
    >
    Oli, Dec 3, 2003
    #3
  4. Oli

    Mike D Guest

    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" <> wrote in message
    news:bqksvp$hss$...
    > 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:...
    > > sql = "SELECT * FROM tblNumbers WHERE AllocatedTo=" & Session("Company")
    > >
    > > RESPONSE.WRITE SQL
    > > RESPONSE.END
    > >
    > > What does that show you?
    > >
    > > Ray at work
    > >
    > >
    > > "Oli" <> wrote in message
    > > news:bqks2u$e7k$...
    > > > 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
    > > >
    > > >

    > >
    > >

    >
    >
    Mike D, Dec 3, 2003
    #4
  5. Oli

    Bob Barrows Guest

    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.
    Bob Barrows, Dec 3, 2003
    #5
  6. Oli

    Oli Guest

    Thanks Guys!


    "Bob Barrows" <> wrote in message
    news:...
    > 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.
    >
    >
    Oli, Dec 3, 2003
    #6
  7. 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
    Bhaskardeep Khaund, Dec 3, 2003
    #7
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. dna
    Replies:
    1
    Views:
    1,264
  2. William \(Bill\) Vaughn
    Replies:
    0
    Views:
    437
    William \(Bill\) Vaughn
    Aug 21, 2003
  3. David Browne
    Replies:
    0
    Views:
    447
    David Browne
    Aug 21, 2003
  4. ecoolone
    Replies:
    0
    Views:
    743
    ecoolone
    Jan 3, 2008
  5. weiwei

    asp and sql statement in sql server db

    weiwei, Sep 22, 2004, in forum: ASP General
    Replies:
    3
    Views:
    193
    Jeff Cochran
    Sep 22, 2004
Loading...

Share This Page