Help a newbie! How do I SELECT using a string as a WHERE clause?

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Help a newbie! How do I SELECT using a string as a WHERE clause?

    Hi,

    I'm having a problem.

    I've found that running a recordset with the query:

    SELECT * FROM user;

    works fine, but as soon as I add a WHERE clause, I get a Jet error.
    (too few parameters).

    I suspect the syntax may be faulty, but I don't know. This is what
    I've got:

    1 .strSQL = "SELECT * FROM user WHERE username=" &
    Request.QueryString("username") & ";"

    2. objRecordSet.Open strSQL,, DB_CONNECTION_STRING, adOpenKeyset,
    adLockPessimistic, adCmdText

    so the string in 1. is being used as the parameter for the command in
    2.

    Only problem is this returns a Too Few Paramters Jet error. As soon
    as I change this to a simple query, as I said before, this works.

    Do I need speech marks in the query?

    Help!

    Pablo.
    Pablo Contreras Guest

  2. Similar Questions and Discussions

    1. where clause as variable string
      I'm building a where clause as a string based on submited form variables. As long as the form variable is an INTEGER the query works fine. If it is...
    2. Using 'IN' clause with mutli-select listbox
      Hi All, Common sense tells me I'm missing something, but I need help here! I have a dynamically populated listbox that I'd like to use to query...
    3. Select from table where field = string
      How to select all lines containg a string (located in $pastmove) in the moves column I tried several ways, for example: $requete="SELECT...
    4. string constants in select
      Bill: You need to rewrite the select as follows: unload to setR.sql delimiter ";" select "alter table " || trim(owner) || "." || trim(tabname)...
    5. DataRow[] and Select(filter with a like clause) question
      I am using the Select method on a DataTable to return a DataRow filter = (width LIKE '%width="%') I am getting an exception saying my filter is...
  3. #2

    Default Re: Help a newbie! How do I SELECT using a string as a WHERE clause?

    Unless your usernames are numeric, you'll need to put single quotes
    around the variable. Like so:

    strUserName = request.querystring("username")
    ' insert code to check that this actually is a username and not an empty
    string or whatever
    strSQL = "Select field1, field2 from user where username = '" &
    strUserName & "'"

    A couple of other things:
    1) You probably don't need those terminating semicolons. Have you tried
    without?
    2) Select * wastes resources on both ends -- the database needs to
    translate that into columns before retrieving them, and the server
    (probably) stores columns you don't need. So you may want to just list
    the columns you need.

    "Pablo Contreras" <pablo@pabs2003.plus.com> wrote in message
    news:d48ohvsbt24cm073rhcj354c3m2imfdput@4ax.com...
    > Hi,
    >
    > I'm having a problem.
    >
    > I've found that running a recordset with the query:
    >
    > SELECT * FROM user;
    >
    > works fine, but as soon as I add a WHERE clause, I get a Jet error.
    > (too few parameters).
    >
    > I suspect the syntax may be faulty, but I don't know. This is what
    > I've got:
    >
    > 1 .strSQL = "SELECT * FROM user WHERE username=" &
    > Request.QueryString("username") & ";"
    >
    > 2. objRecordSet.Open strSQL,, DB_CONNECTION_STRING, adOpenKeyset,
    > adLockPessimistic, adCmdText
    >
    > so the string in 1. is being used as the parameter for the command in
    > 2.
    >
    > Only problem is this returns a Too Few Paramters Jet error. As soon
    > as I change this to a simple query, as I said before, this works.
    >
    > Do I need speech marks in the query?
    >
    > Help!
    >
    > Pablo.

    Kris Eiben Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139