Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JScript ASP problem - Displaying contents of RecordSet

Status
Not open for further replies.

dunxd

Programmer
Jul 29, 2002
44
GB
I create a record set as follows:
Code:
rs = Server.CreateObject("ADODB.Recordset");
sql = "SELECT id,text WHERE id = 1";
rs.Open(sql,my_connection);
The recordset rs should contain the following.
[ul]
[li]rs("id")[/li]
[li]rs("text")[/li]
[/ul]
I now want to display the contents of my recordset.

There is no problem if I want to display as follows:
Code:
<p><%=rs(&quot;id&quot;)%></p>
<p><%=rs(&quot;text&quot;)%></p>
But if I try to do it in a different order:
Code:
<p><%=rs(&quot;text&quot;)%></p>
<p><%=rs(&quot;id&quot;)%></p>
The second paragraph will be blank!

Obviously this is not a big deal when dealing with a recordset containing only a few fields, but as soon as I start doing more complex selects (ie use * to get all fields, use calculated fields, specify a lot of fields) things become problematic.

Can anyone tell me if I am doing something wrong, or if there is a simple workaround to this problem.

Cheers --
Dunx
 
[tt]Try looping thru the recordset then display your variables in any order...
[sup]
<%=Tony%>
banana.gif
rockband.gif
banana.gif
 
Another method is to use the ordinal position in the recordset. Based on your Select statement above, you could try

<p><%=rs(0)%></p> <!-- ID -->
<p><%=rs(1)%></p> <!-- Text -->

or

<p><%=rs(1)%></p> <!-- Text -->
<p><%=rs(0)%></p> <!-- ID -->

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top