Retrieving ADO Record Names (Classic ASP)

I wonder if anyone can help:

In short, I use MSSQL2005 to create a pivot table. The studied data is limited by the date range (all data within 1 week from the nearest Monday to the selected date)

When I start Stored Proc and pass the date to it, I get the correct table back, for example:

Time | Jan 1 09 | Jan 2 09 | Jan 3 09 | ...

09:00 | 0 | 9 | 25 | ...

09:30 | 8 | 27 | 65 | ...

10:00 | 20 | 44 | 112 | ...

(Apologies for the disgusting formatting of the table).

The only problem I encountered is that the column headers will change depending on the date passed to the SP (desired presentation date) and the logic inside the SP (which forces the left column to be the closest Monday to the specified date).

This means that when I show the results to the user, I (currently) have to duplicate the date check logic in the classic ASP [easy, but maintainability failure]

I really need a way to get the column names from the record set itself.

Can anyone point me in the right direction?

I have Googled, but all the results that I get seem to relate to reading the table schema, which in this case does not help, since my table is generated "on the fly" in memory.

Thanks so much for any help you can provide.

+6
ado asp-classic pivot recordset
source share
2 answers

Given the ado recordset, you can do something like this (this is in psuedo code):

foreach (field in rs.Fields) { alert(field.Name); } 

This will give you the field name to check this documentation .

+7
source share

Something like this should do this: -

  <table> <thead> <tr> <%For Each fld in rst.Fields%> <th><span><%=Server.HTMLEncode(fld.Name)%></span></th> <%Next %> </tr> </thead> <tbody> <% Do Until rst.EOF OutputRow rst.Fields rst.MoveNext Loop %> </tbody> </table> Sub OutputRow(fields) %> <tr> <%For Each fld in fields%> <td><span><%=Server.HTMLEncode(fld.Name)%></span></td> <%Next %> </tr> <% End Sub %> 
+4
source share

All Articles