AspGerman Wiki

Oft brauch ich mal eben Code um eine Tabelle auf die Schnelle auszugeben. Hier ein Beispiel, das ich so kopieren und einfügen kann. Connection String und SQL Query anpassen und los geht es.

sSQL = "SELECT * FROM tabelle"
sConn = "..."

Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open sConn
Set oRs = oConn.Execute(sSQL)

' -- Tabellenkopf
Response.write "<table cellspacing=""0"" cellpadding=""2"">" & vbcrlf & "<tr>" & vbcrlf
For Index=0 to (oRs.fields.count - 1)
	Response.write("<th>" & oRs(Index).Name & "</th>") & vbcrlf
Next
Response.write("<tr>") & vbcrlf

' -- Tabelle
sColorcount = 1
Do Until oRs.eof
	Response.write("<tr>") & vbcrlf
	If (sColorcount and 1) = 0 Then
		sColorstyle = " style=""background-color: silver"""
	Else
		sColorstyle = ""
	End If
	For Index=0 to (oRs.fields.count-1)
		Response.write("<td" & sColorstyle  & ">" & oRs(Index).value & "&nbsp;</td>") & vbcrlf
	Next
	Response.write("</tr>") & vbcrlf
		oRs.MoveNext
	sColorcount = sColorcount + 1
Loop

' -- Tabellenende
Response.write("</table>") & vbcrlf

oRs.close
oConn.close

ScrewTurn Wiki version 2.0.33. Some of the icons created by FamFamFam.