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

SQL Field Name

Status
Not open for further replies.

Esoteric

ISP
Feb 10, 2001
93
US
I know there is a way to have ASP print a list of fields from a given table. Can someone post the code for me Please!

 
Here ya go, just plug in this function and make sure you add the record set to it like so:

Response.Write BuildTable(your_object_with_recordset_already_queried)

This will build ya a nice little table ... or maybe not so little if you've got HUGE fields. =D

I use this to test queries often times and if I forget the field names at times as well and I'm too lazy to open the database itself. =)

Code:
Function BuildTable (objRec)

    Dim intLoop
    Dim strTable, strField

    strTable = &quot;<table border=1 cellpadding=0 cellspacing=0><tr align=center>&quot;

    ' Building Column Names

    For Each strField In objRec.Fields
        strTable = strTable & &quot;<td>&quot; & strField.Name & &quot;</td>&quot;
    Next

    strTable = strTable & &quot;<td>AbsolutePos</td></tr>&quot;

    ' Building the Rows

    'For intLoop = 1 to 20
    While Not objRec.EOF
        strTable = strTable & &quot;<tr align=center>&quot;
        For Each strField In ObjRec.Fields
            strTable = strTable & &quot;<td>&quot; & strField.Value & &quot; </td>&quot;
        Next
        strTable = strTable & &quot;<td>&quot; & objRec.AbsolutePosition & &quot;</td></tr>&quot;
        objRec.MoveNext
    Wend
    'Next
    strTable = strTable & &quot;</table>&quot;
    BuildTable = strTable

End Function
Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Darnit, my fault this time ... There are 2 things to this little function that I did. If you're table has few records, let's say less than 50, leave it as is. If you have like millions of records, don't run it as is. Notice there is a FOR NEXT loop in the BUILD ROWS section of the function. Uncomment the FOR and the NEXT and then comment out the WHILE and the WEND and it will only loop through the first 20 records.

PHEW ... hope I didn't make you dump a million + records to a web page. =D

Hope this works and sorry about that oversight. Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Okay, I got the Field.Name but can I get the DataType for the Field?

Say for like Date or Time or integer or nvchar?

I got the other working and btw, I realized that before I ran it (good thing with 500,000 plus records :))
 
Just ask for the rs(&quot;fieldName&quot;).type --

Will return an integer value that will correspond to the DataTypeEnum enumerators that you can find at
I guess you could make function or something that would return string values instead of the integer values.

(I think you can find those values in the adovbs.inc file, as well)

Paul Prewett
 
Thanks Paul (link9). I was out to lunch (Bourbon Chicken at Cajun Grill is great!) and just got back to my office. Now that you pointed that out, I might add a little loop right after the titles so it shows the type right under it. I didn't do it before but I never really had the need. Would make for a great little help tool. :) Ed (RoadRacer) Holguin

&quot;I Hate Computers!&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top