Results 1 to 3 of 3
  1. #1
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Display Column Name and Field Value in ASP (Access2K, Win2KPro)

    I'd think this is simple but I am... <img src=/S/hairout.gif border=0 alt=hairout width=31 height=23>

    I am trying to read a row in an Access db and display the column names and field values in an ASP page. I can get the column names using <font face="Georgia">ADOX.Catalog</font face=georgia> and can get the field values using standard recordset stuff but I can't seem to get both at once. any ideas??

    TIA

  2. #2
    Bronze Lounger
    Join Date
    Nov 2001
    Location
    Arlington, Virginia, USA
    Posts
    1,394
    Thanks
    0
    Thanked 3 Times in 3 Posts

    Re: Display Column Name and Field Value in ASP (Access2K, Win2KPro)

    If using an ADO recordset recommend use ADO Field object's Name property to return name of field. No need for ADOX. From ADO Help:
    <hr>To refer to a Field object in a collection by its ordinal number or by its Name property setting, use any of the following syntax forms:

    Fields(0)
    Fields("name")
    Fields![name]

    With the same syntax forms, you can also refer to the Value property of a Field object that you create and append to a Fields collection. The context of the field reference will determine whether you are referring to the Field object or the Value property of the Field object.<hr>
    Not too familiar with ASP but should be able to reference field names when generating ASP page. When copying recordset to Excel, I use same method, ie, use Field names for column headings in Excel file, then CopyRecordset.

    HTH

  3. #3
    5 Star Lounger
    Join Date
    Jan 2001
    Location
    austin, Texas, USA
    Posts
    1,029
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Display Column Name and Field Value in ASP (Access2K, Win2KPro)

    urrgggh...it worked! and I swear I'd tried this before. must have done *something* wrong.

    this is the ur-code:
    <font face="Georgia">
    mySQL = "SELECT * FROM qry_MPI_EMail WHERE ComplainantID = 152;"
    myRS.Open mySQL, DataConnection, adOpenStatic, adCmdTable

    for each field in myRS.fields
    if instr(field.name, "Allegation_") > 0 then
    if field = "1" then
    response.write field.name & "< br >"
    end if
    end if
    next</font face=georgia>

    Just goes to show, simple is (usually) better! <img src=/S/clown.gif border=0 alt=clown width=15 height=15>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •