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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Display full contents of database with a simple script 1

Status
Not open for further replies.

jollyreaper

Technical User
Jul 25, 2005
105
US
I know that there's a way to do this, I know my pseudocode should be close (hopefully) to correct.

I want to be able to take a given table from the database and display all records for all fields without having to manually type in the field names. I remember that you're supposed to be able to reference the fields by number as well.

'database connection jibber jabber
Set RS = Connection.Execute("select * from mytable")
<%
'me looping through all records in the database
While (NOT rs.EOF)
%>
<table width="494" height="222" border="1">
<tr>
<%'display all fields in record
fieldmax=some function to determine # of fields in table, how?!?
set fieldnum=1
while (fieldnum>=fieldmax)
<td><%=RS.Fields("somehow print fieldname for field x, how?!") </td>
<td><%= RS.Fields(fieldnum)%></td>
<%fieldnum=fieldnum+1
wend
%>
</tr>
</table>
<%rs.MoveNext
wend
%>

In case anyone is wondering what the goal here is, we've got people external to the company who need access to data from our database and given the situation, it's easier to put it in xml on an https webserver than any other solution we could come up with. I left the xml out of the example to simplify things.

Any feedback would be greatly appreciated!
 
something like this:

Code:
	strSQL = " your sql statement "

	rsObj.Open strSQL, MdConnection
	
	Response.Write "<table border=1>"
    If Not rsObj.EOF Then
        Response.Write "<tr>"
        For x = 0 To rsObj.Fields.Count - 1
            Response.Write "<th>" & rsObj(x).Name & "</th>"
            Response.Flush()
        Next
        Response.Write "</tr>"
        
        Do While Not rsObj.EOF
            Response.Write "<tr>"
            For x = 0 To rsObj.Fields.Count - 1
                Response.Write "<td>" & rsObj(x)& "&nbsp;</td>"
            Next
            Response.Write "</tr>"
            rsObj.MoveNext
        Loop
    End If
    Response.Write "</table>"

-DNG
 
The Fields collection has a Count property. Each member of the Fields collection has a Name property

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top