Recordset elements failing to write to page

Discussion in 'ASP General' started by Greg Hurlman, Sep 3, 2003.

  1. Greg Hurlman

    Greg Hurlman Guest

    I've got what I'm sure is a very simple problem. In an ASP page, I am trying
    to write out 4 fields from a recordset in succession:

    Response.Write rs("LastName")
    Response.Write rs("Suffix")
    Response.Write rs("FirstName")
    Response.Write rs("MiddleInitial")

    All fields are populated and are single terms. I would expect
    "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test record) to
    be written out on the page. However, all I get is "LastNameSuffix"
    (UserIII). If I move the FirstName and/or MiddleInitial to be written
    first, I get "TestAUserIII".

    What is the deal?

    Please respond to the group, but email is ok too, just switch the username
    and domain name in the address.

    Thanks,
    Greg
    Greg Hurlman, Sep 3, 2003
    #1
    1. Advertising

  2. Greg Hurlman

    Bob Barrows Guest

    Are any Memo fields involved? This sounds like the bug described here:
    http://www.aspfaq.com/show.asp?id=2188

    Greg Hurlman wrote:
    > I've got what I'm sure is a very simple problem. In an ASP page, I am
    > trying to write out 4 fields from a recordset in succession:
    >
    > Response.Write rs("LastName")
    > Response.Write rs("Suffix")
    > Response.Write rs("FirstName")
    > Response.Write rs("MiddleInitial")
    >
    > All fields are populated and are single terms. I would expect
    > "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test
    > record) to be written out on the page. However, all I get is
    > "LastNameSuffix" (UserIII). If I move the FirstName and/or
    > MiddleInitial to be written first, I get "TestAUserIII".
    >
    > What is the deal?
    >
    > Please respond to the group, but email is ok too, just switch the
    > username and domain name in the address.
    >
    > Thanks,
    > Greg
    Bob Barrows, Sep 3, 2003
    #2
    1. Advertising

  3. Show your code.


    "Greg Hurlman" <> wrote in message
    news:el#...
    > I've got what I'm sure is a very simple problem. In an ASP page, I am

    trying
    > to write out 4 fields from a recordset in succession:
    >
    > Response.Write rs("LastName")
    > Response.Write rs("Suffix")
    > Response.Write rs("FirstName")
    > Response.Write rs("MiddleInitial")
    >
    > All fields are populated and are single terms. I would expect
    > "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test record)

    to
    > be written out on the page. However, all I get is "LastNameSuffix"
    > (UserIII). If I move the FirstName and/or MiddleInitial to be written
    > first, I get "TestAUserIII".
    >
    > What is the deal?
    >
    > Please respond to the group, but email is ok too, just switch the username
    > and domain name in the address.
    >
    > Thanks,
    > Greg
    >
    >
    Aaron Bertrand - MVP, Sep 3, 2003
    #3
  4. Greg Hurlman

    Ray at Guest

    What's in your View-Source?

    Also, try

    Response.Write Server.HTMLEncode(rs.Fields.Item(0).Value)
    Response.Write Server.HTMLEncode(rs.Fields.Item(1).Value)
    Response.Write Server.HTMLEncode(rs.Fields.Item(2).Value)
    Response.Write Server.HTMLEncode(rs.Fields.Item(3).Value)

    What does that yield?

    Ray at work




    "Greg Hurlman" <> wrote in message
    news:el%...
    > I've got what I'm sure is a very simple problem. In an ASP page, I am

    trying
    > to write out 4 fields from a recordset in succession:
    >
    > Response.Write rs("LastName")
    > Response.Write rs("Suffix")
    > Response.Write rs("FirstName")
    > Response.Write rs("MiddleInitial")
    >
    > All fields are populated and are single terms. I would expect
    > "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test record)

    to
    > be written out on the page. However, all I get is "LastNameSuffix"
    > (UserIII). If I move the FirstName and/or MiddleInitial to be written
    > first, I get "TestAUserIII".
    >
    > What is the deal?
    >
    > Please respond to the group, but email is ok too, just switch the username
    > and domain name in the address.
    >
    > Thanks,
    > Greg
    >
    >
    Ray at, Sep 3, 2003
    #4
  5. Greg Hurlman

    Greg Hurlman Guest

    This yields the same result.

    Also, from my View->Source...

    <td>
    UserIII
    </td>

    Where User is LastName, and III is Suffix.

    Thanks,
    Greg

    "Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
    news:%...
    > What's in your View-Source?
    >
    > Also, try
    >
    > Response.Write Server.HTMLEncode(rs.Fields.Item(0).Value)
    > Response.Write Server.HTMLEncode(rs.Fields.Item(1).Value)
    > Response.Write Server.HTMLEncode(rs.Fields.Item(2).Value)
    > Response.Write Server.HTMLEncode(rs.Fields.Item(3).Value)
    >
    > What does that yield?
    >
    > Ray at work
    >
    >
    >
    >
    > "Greg Hurlman" <> wrote in message
    > news:el%...
    > > I've got what I'm sure is a very simple problem. In an ASP page, I am

    > trying
    > > to write out 4 fields from a recordset in succession:
    > >
    > > Response.Write rs("LastName")
    > > Response.Write rs("Suffix")
    > > Response.Write rs("FirstName")
    > > Response.Write rs("MiddleInitial")
    > >
    > > All fields are populated and are single terms. I would expect
    > > "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test

    record)
    > to
    > > be written out on the page. However, all I get is "LastNameSuffix"
    > > (UserIII). If I move the FirstName and/or MiddleInitial to be written
    > > first, I get "TestAUserIII".
    > >
    > > What is the deal?
    > >
    > > Please respond to the group, but email is ok too, just switch the

    username
    > > and domain name in the address.
    > >
    > > Thanks,
    > > Greg
    > >
    > >

    >
    >
    Greg Hurlman, Sep 3, 2003
    #5
  6. Greg Hurlman

    Bob Barrows Guest

    Create a page with just the following server-side code in it (no html
    stuff). Run it and let us know if you get the same result.

    Bob

    Greg Hurlman wrote:
    > My code:
    >
    > Option Explicit
    > Response.Buffer = True
    >
    > Dim rs, ID, SQL, cn, UserID
    >
    > Set cn = Server.CreateObject("ADODB.Connection")
    > cn.Open Application("DSN")
    > SQL = "select * from RegisteredUsers where UserID='" & UserID & "'"
    > Set rs = cn.Execute(SQL)
    >
    > Response.Write rs("FirstName")
    > Response.Write rs("LastName")
    > Response.Write rs("Suffix")
    > Response.Write rs("MiddleInitial")
    > ...
    >
    > I've left out HTML formatting code, but the code above represents all
    > DB interaction.
    >
    > Thanks,
    > Greg
    >
    >
    > "Aaron Bertrand - MVP" <> wrote in message
    > news:...
    >> Show your code.
    >>
    >>
    >> "Greg Hurlman" <> wrote in message
    >> news:el#...
    >>> I've got what I'm sure is a very simple problem. In an ASP page, I
    >>> am trying to write out 4 fields from a recordset in succession:
    >>>
    >>> Response.Write rs("LastName")
    >>> Response.Write rs("Suffix")
    >>> Response.Write rs("FirstName")
    >>> Response.Write rs("MiddleInitial")
    >>>
    >>> All fields are populated and are single terms. I would expect
    >>> "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test
    >>> record) to be written out on the page. However, all I get is
    >>> "LastNameSuffix" (UserIII). If I move the FirstName and/or
    >>> MiddleInitial to be written first, I get "TestAUserIII".
    >>>
    >>> What is the deal?
    >>>
    >>> Please respond to the group, but email is ok too, just switch the
    >>> username and domain name in the address.
    >>>
    >>> Thanks,
    >>> Greg
    Bob Barrows, Sep 3, 2003
    #6
  7. Okay, now try:

    <%
    set conn = CreateObject("ADODB.Connection")
    conn.open "<use a connection string from http://www.aspfaq.com/2126, not
    an ODBC DSN>"
    sql = "SELECT FirstName, LastName, Suffix, MiddleInitial" & _
    " FROM RegisteredUsers WHERE UserID = '" & UserID & "'"
    response.write sql & "<p>"
    set rs = conn.execute(sql)
    if not rs.eof then
    response.write rs("FirstName") & "<br>"
    response.write rs("LastName") & "<br>"
    response.write rs("Suffix") & "<br>"
    response.write rs("MiddleInitial") & "<br>"
    else
    response.write "Empty RS"
    end if
    rs.close: set rs = nothing
    conn.close: set conn = nothing
    %>

    Key changes: (a) use an OLE-DB connection string, not a crappy DSN, (b)
    *NAME* your columns, instead of lazy SELECT *, (c) test for EOF, (d) inspect
    the actual SQL statement you're running (I don't see where you populate
    UserID in your script).

    Also, if UserID is a string, it is poorly named, IMHO. Appended "ID"
    usually indicates a numeric column. If UserID is in fact a number, then
    remove the single quotes around it.



    "Greg Hurlman" <> wrote in message
    news:...
    > My code:
    >
    > Option Explicit
    > Response.Buffer = True
    >
    > Dim rs, ID, SQL, cn, UserID
    >
    > Set cn = Server.CreateObject("ADODB.Connection")
    > cn.Open Application("DSN")
    > SQL = "select * from RegisteredUsers where UserID='" & UserID & "'"
    > Set rs = cn.Execute(SQL)
    >
    > Response.Write rs("FirstName")
    > Response.Write rs("LastName")
    > Response.Write rs("Suffix")
    > Response.Write rs("MiddleInitial")
    > ...
    >
    > I've left out HTML formatting code, but the code above represents all DB
    > interaction.
    >
    > Thanks,
    > Greg
    >
    >
    > "Aaron Bertrand - MVP" <> wrote in message
    > news:...
    > > Show your code.
    > >
    > >
    > > "Greg Hurlman" <> wrote in message
    > > news:el#...
    > > > I've got what I'm sure is a very simple problem. In an ASP page, I am

    > > trying
    > > > to write out 4 fields from a recordset in succession:
    > > >
    > > > Response.Write rs("LastName")
    > > > Response.Write rs("Suffix")
    > > > Response.Write rs("FirstName")
    > > > Response.Write rs("MiddleInitial")
    > > >
    > > > All fields are populated and are single terms. I would expect
    > > > "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test

    > record)
    > > to
    > > > be written out on the page. However, all I get is "LastNameSuffix"
    > > > (UserIII). If I move the FirstName and/or MiddleInitial to be written
    > > > first, I get "TestAUserIII".
    > > >
    > > > What is the deal?
    > > >
    > > > Please respond to the group, but email is ok too, just switch the

    > username
    > > > and domain name in the address.
    > > >
    > > > Thanks,
    > > > Greg
    > > >
    > > >

    > >
    > >

    >
    >
    Aaron Bertrand - MVP, Sep 3, 2003
    #7
  8. Greg Hurlman

    Greg Hurlman Guest

    I implemented these changes one at a time, and moving from a DSN to a
    connection string seems to have done the trick... in hindsight, this is
    exactly the punishment the ASP gods should have given me for ignoring my
    better judgement re: dsn after inheriting an old application.

    Thanks for your help,
    Greg

    "Aaron Bertrand - MVP" <> wrote in message
    news:%...
    > Okay, now try:
    >
    > <%
    > set conn = CreateObject("ADODB.Connection")
    > conn.open "<use a connection string from http://www.aspfaq.com/2126,

    not
    > an ODBC DSN>"
    > sql = "SELECT FirstName, LastName, Suffix, MiddleInitial" & _
    > " FROM RegisteredUsers WHERE UserID = '" & UserID & "'"
    > response.write sql & "<p>"
    > set rs = conn.execute(sql)
    > if not rs.eof then
    > response.write rs("FirstName") & "<br>"
    > response.write rs("LastName") & "<br>"
    > response.write rs("Suffix") & "<br>"
    > response.write rs("MiddleInitial") & "<br>"
    > else
    > response.write "Empty RS"
    > end if
    > rs.close: set rs = nothing
    > conn.close: set conn = nothing
    > %>
    >
    > Key changes: (a) use an OLE-DB connection string, not a crappy DSN, (b)
    > *NAME* your columns, instead of lazy SELECT *, (c) test for EOF, (d)

    inspect
    > the actual SQL statement you're running (I don't see where you populate
    > UserID in your script).
    >
    > Also, if UserID is a string, it is poorly named, IMHO. Appended "ID"
    > usually indicates a numeric column. If UserID is in fact a number, then
    > remove the single quotes around it.
    >
    >
    >
    > "Greg Hurlman" <> wrote in message
    > news:...
    > > My code:
    > >
    > > Option Explicit
    > > Response.Buffer = True
    > >
    > > Dim rs, ID, SQL, cn, UserID
    > >
    > > Set cn = Server.CreateObject("ADODB.Connection")
    > > cn.Open Application("DSN")
    > > SQL = "select * from RegisteredUsers where UserID='" & UserID & "'"
    > > Set rs = cn.Execute(SQL)
    > >
    > > Response.Write rs("FirstName")
    > > Response.Write rs("LastName")
    > > Response.Write rs("Suffix")
    > > Response.Write rs("MiddleInitial")
    > > ...
    > >
    > > I've left out HTML formatting code, but the code above represents all DB
    > > interaction.
    > >
    > > Thanks,
    > > Greg
    > >
    > >
    > > "Aaron Bertrand - MVP" <> wrote in message
    > > news:...
    > > > Show your code.
    > > >
    > > >
    > > > "Greg Hurlman" <> wrote in message
    > > > news:el#...
    > > > > I've got what I'm sure is a very simple problem. In an ASP page, I

    am
    > > > trying
    > > > > to write out 4 fields from a recordset in succession:
    > > > >
    > > > > Response.Write rs("LastName")
    > > > > Response.Write rs("Suffix")
    > > > > Response.Write rs("FirstName")
    > > > > Response.Write rs("MiddleInitial")
    > > > >
    > > > > All fields are populated and are single terms. I would expect
    > > > > "LastNameSuffixFirstNameMiddleInitial" ("UserIIITestA" in my test

    > > record)
    > > > to
    > > > > be written out on the page. However, all I get is "LastNameSuffix"
    > > > > (UserIII). If I move the FirstName and/or MiddleInitial to be

    written
    > > > > first, I get "TestAUserIII".
    > > > >
    > > > > What is the deal?
    > > > >
    > > > > Please respond to the group, but email is ok too, just switch the

    > > username
    > > > > and domain name in the address.
    > > > >
    > > > > Thanks,
    > > > > Greg
    > > > >
    > > > >
    > > >
    > > >

    > >
    > >

    >
    >
    Greg Hurlman, Sep 3, 2003
    #8
    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. Gian Paolo Clarici
    Replies:
    0
    Views:
    792
    Gian Paolo Clarici
    Jul 21, 2004
  2. Hung Huynh
    Replies:
    8
    Views:
    301
    Bob Barrows
    Sep 24, 2003
  3. Fawke101

    Response.write RecordSet values

    Fawke101, Apr 21, 2004, in forum: ASP General
    Replies:
    4
    Views:
    348
    Ray at
    Apr 21, 2004
  4. Oscar
    Replies:
    27
    Views:
    478
    Mark J. McGinty
    Jun 1, 2005
  5. Replies:
    3
    Views:
    150
    Bob Barrows [MVP]
    Jan 23, 2007
Loading...

Share This Page