Solved

Using ADO to retrieve field captions

Posted on 2001-08-21
9
345 Views
Last Modified: 2012-06-21
Some code:

<%

Dim rs, conn
Set rs = Server.CreateObject("ADODB.Recordset")
Set conn = Server.CreateObject("ADODB.Connection")

conn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("database.mdb")

conn.Open

rs.Open "SELECT * FROM MyTable", conn, 2, 3

' If I wanted to retrieve the field NAMES I would do this

For Each fld In rs.Fields
   Response.Write fld.Name & "<br>" & vbCr
Next

' But I want to retrieve the field's
' caption or description!
%>

So in design view my database looks like this:

Field ------ Type ------ Description
Username --- Text ------ The username on this account
Password --- Text ------ The password matching username

I want my for loop to output "The username on this account" and "The password matching username" instead of Username and Password.

Thanks in advance.

Dan
0
Comment
Question by:SuperMario
  • 2
  • 2
  • 2
  • +3
9 Comments
 
LVL 3

Author Comment

by:SuperMario
ID: 6410760
I wish they had a way to include <FONT FACE="Fixedsys">fixed-width</FONT> font styles.
0
 
LVL 7

Expert Comment

by:John844
ID: 6410830
This feature in access in not supported in all other databases.  I don't think ado has any builtin capabilities to read this property of a field.  You might look into dao which is more access specific, but not optimized for web usage.

John
0
 
LVL 5

Expert Comment

by:raizon
ID: 6411130
Use this.

<%

Dim rs, conn
Set rs = Server.CreateObject("ADODB.Recordset")
Set conn = Server.CreateObject("ADODB.Connection")

conn.ConnectionString = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.MapPath("database.mdb")

conn.Open

rs.Open "SELECT * FROM MyTable", conn, 2, 3

Set Fields = rs.Fields

' If I wanted to retrieve the field NAMES I would do this

For Each fld In Fields
  Response.Write fld.Name & "<br>" & vbCr
Next

' But I want to retrieve the field's
' caption or description!
%>
0
 
LVL 20

Expert Comment

by:jitganguly
ID: 6411132
Actually it is do-able. I was answering a same question in SQLServer, but mgfranz came up with his briliant idea of using Ole db. Check this
Use COLUMN_SIZE,with COLUMN_NAME and TABLE_NAME

<%    
Set conn = Server.CreateObject("ADODB.Connection")
conn.ConnectionTimeout = 15
conn.CommandTimeout =  10
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & Server.MapPath("data/database.mdb")
   Set rstSchema1 = conn.OpenSchema(4)
   Do Until rstSchema1.EOF
   Response.Write "<BR>Table name : " & rstSchema1("TABLE_NAME") _
& vbCrLf & ", Column Name : " & rstSchema1("COLUMN_NAME") & vbCrLf
   rstSchema1.MoveNext
   Loop
   rstSchema1.Close
conn.Close
%>
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
LVL 2

Expert Comment

by:AccessHelpNet
ID: 6416051
jitjanguy is right and should get points, however he neglected to put in his code the statement I think you are most interested in:

Response.write rstSchema1("DESCRIPTION")

As far as I have seen this only works in Access.  Populating the DESCRIPTION is optional for OLEDB providers, however, both OLEDB for ODBC and native JETOLEDB drivers seem to support it just fine.

regards,

Dave Kawliche
http://AccessHelp.net
http://1ClickDB.com
0
 
LVL 3

Author Comment

by:SuperMario
ID: 6423610
Thanks Access...
That's precisely what I need.

Who do you guys think deserves the points?

-Dan
0
 
LVL 2

Expert Comment

by:AccessHelpNet
ID: 6423635
My vote is for jitganguly

regards,

Dave Kawliche
http://AccessHelp.net
http://1ClickDB.com
0
 
LVL 20

Accepted Solution

by:
jitganguly earned 50 total points
ID: 6423653
Yes, I deserve points here :-)
0
 
LVL 33

Expert Comment

by:hongjun
ID: 8630943
AccessHelpNet or robbert, how about the "Caption"? I can't get the caption. "COLUMN_NAME" gives me the column name and not the caption. I found this question using search.

hongjun
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Hello, all! I just recently started using Microsoft's IIS 7.5 within Windows 7, as I just downloaded and installed the 90 day trial of Windows 7. (Got to love Microsoft for allowing 90 days) The main reason for downloading and testing Windows 7 is t…
Have you ever needed to get an ASP script to wait for a while? I have, just to let something else happen. Or in my case, to allow other stuff to happen while I was murdering my MySQL database with an update. The Original Issue This was written…
This Micro Tutorial will teach you how to censor certain areas of your screen. The example in this video will show a little boy's face being blurred. This will be demonstrated using Adobe Premiere Pro CS6.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …

911 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now