RS(fieldname) error when using column alias.

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

  1. #1

    Default RS(fieldname) error when using column alias.

    Could someone tell me why I cannot seem to reference a field in a
    record set which I have given an alias to. I have given the field
    c.firstname an alias of firstname but my RS function cannot find it
    (it errors with undefines name etc). Is there something different
    about referencing an alias to a field or something different when
    joining table with a prefix eg: c.firstname. Code is below.

    Thanks
    Lee


    Call OPEN_DB()

    SQL = "SELECT p.profileid as profileid ,c.firstname as firstname
    ,c.lastname as lastname FROM customers c, profiles p WHERE p.profileid
    = " & profileid & " and c.customerid = p.customerid;"

    Set RS = MyConn.Execute(SQL)

    firstname = RS(firstname)

    RS.Close
    Lee Farrant Guest

  2. Similar Questions and Discussions

    1. #33809 [Com]: pg_fetch_result: table alias produces invalid column result error
      ID: 33809 Comment by: alan8 at maths dot topology dot org Reported By: torpedo51 at yahoo dot com Status: No...
    2. Given fieldname could not be found in the table.
      Another newbie question here. I am trying to update one table ("Table A") and insert into another table ("Table B"): <cfquery DATASOURCE="tech...
    3. column alias help
      per the CFMX7 livedocs: One way to create an alias is to concatenate (append) two or more columns to generate a value. For example, you can...
    4. dbase: how to get fieldNAME ofa table
      Hello, below you will find a simple script that reads out info of a dbase It reads out all the records and every field of the record. For my...
  3. #2

    Default Re: RS(fieldname) error when using column alias.

    Lee Farrant wrote:
    > Could someone tell me why I cannot seem to reference a field in a
    > record set which I have given an alias to. I have given the field
    > c.firstname an alias of firstname but my RS function cannot find it
    > (it errors with undefines name etc). Is there something different
    > about referencing an alias to a field or something different when
    > joining table with a prefix eg: c.firstname. Code is below.
    >
    > Thanks
    > Lee
    >
    >
    > Call OPEN_DB()
    >
    > SQL = "SELECT p.profileid as profileid ,c.firstname as firstname
    > ,c.lastname as lastname FROM customers c, profiles p WHERE p.profileid
    > = " & profileid & " and c.customerid = p.customerid;"
    >
    > Set RS = MyConn.Execute(SQL)
    >
    > firstname = RS(firstname)
    >
    > RS.Close
    There are two ways to reference an item in the Fields collection:
    1. By using its zero-based index, or by using a variable/constant containing
    that index. This is the most efficient way of referring to an item in a
    collection.
    So, to get the second field object you can do this:
    rs(1)

    or use a constant like this (you could also Dim a variable instead of using
    a constant, but using the constant is more efficient):
    const secondfield=1
    rs(secondfield)

    2. By using the name of the field, or a variable containing the name of the
    field. To get the value of the field named thisfield, you can either use a
    literal string like this:
    rs("thisfield")

    or use a constant like this:
    const fieldname="thisfield"
    rs(fieldname)

    Bottom line: put quotes around the word "firstname" so that vbscript does
    not think you are using a variable/constant.

    HTH,
    Bob Barrows
    --
    Microsoft MVP - ASP/ASP.NET
    Please reply to the newsgroup. This email account is my spam trap so I
    don't check it very often. If you must reply off-line, then remove the
    "NO SPAM"


    Bob Barrows Guest

  4. #3

    Default Re: RS(fieldname) error when using column alias.

    thanks,
    Lee




    *** Sent via Developersdex [url]http://www.developersdex.com[/url] ***
    Don't just participate in USENET...get rewarded for it!
    Lee Farrant 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