Yes, it's time for some ASP 3/Classic content. Okay, I confess, this post is mostly just a reminder for myself in the future...but I assume at some point someone will come across this via google....
I was wondering what the easiest way to traverse a recordset was (not most performant, necessarily...just simplest in terms of me saving time) I commonly see people actually writing out the table and then explicitly defining which column goes where. You know, something like:
objRs(0) | objRs(1) |
Which, really, is kind of a pain in the arse. You could just do something like this if it's just a simple output to a table, and not really worry about too much HTML, provided your query columns are in the order you want them displayed.
SearchString = “whatever..“
Set objRS = objConnection.Execute(SearchString)
Do While Not objRS.EOF
i = i + 1
if i mod 2 = 0 then varClass = "light" else varClass = "med" 'just to change styles...
for x=0 to objRS.Fields.count-1
response.write "
" & objRS(x) &" | "
next
response.write ""
objRS.MoveNext
Loop
Another handy bit of code for debugging request() parameters is the following. Much easier than actually response.write() -ing all the variables out manually...
For x = 1 to Request.Form.Count
Response.Write Request.Form.Key(x) & " = "
Response.Write Request.Form.Item(x) & "
"
Next
Here is an easy one for populating select lists...
Sub PopulateSelectOptions(ByVal objRecordset, ByVal varCurrentID, varBlankLine)
Dim varHTML
Dim varSelected
If Not objRecordSet.EOF Then objRecordSet.MoveFirst
If varBlankLine Then varHTML = "<OPTION VALUE=0></OPTION>" Else varHTML = ""
Do While Not objRecordset.EOF
If Not IsNull(varCurrentID) Then
If CLng(varCurrentID) = Clng(objRecordset.Fields(0)) Then
varSelected = " SELECTED"
Else
varSelected = ""
End If
Else
varSelected = ""
End if
varHTML = varHTML & "<OPTION VALUE=" & objRecordset.Fields(0) & varSelected & ">" & objRecordset.Fields(1) & "</OPTION>"
objRecordset.MoveNext
Loop
If IsNull(varHTML) And Len(varHTML) < 0 Then
varHTML = "<OPTION>-No-</OPTION>"
Response.Write varHTML
Else
Response.Write varHTML
End if
End Sub
Print | posted on Friday, August 18, 2006 7:20 PM