Recordset elements failing to write to page

G

Greg Hurlman

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
 
R

Ray at

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
 
G

Greg Hurlman

This yields the same result.

Also, from my View->Source...

<td>
UserIII
</td>

Where User is LastName, and III is Suffix.

Thanks,
Greg
 
B

Bob Barrows

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
 
A

Aaron Bertrand - MVP

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

Greg Hurlman

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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,767
Messages
2,569,570
Members
45,045
Latest member
DRCM

Latest Threads

Top