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

Fields name from a table. 1

Status
Not open for further replies.

Kendel

Programmer
Apr 24, 2002
1,512
US
Hi,

I need to query field names from my table & table names in my database. Can someone help me out?

Thanks.
 
sql = "Select table_field from mytable where name_field = "AKA"

pinky1.jpg width='75' height='75'
[/tt]
056.jpg
 
or
sql = "Select * from mytable where name_field = "AKA"

or

sql = "Select * from mytable where name_field = request.form("field_name_from_the_form")


pinky1.jpg width='75' height='75'
[/tt]
056.jpg
 
That's not what I'm looking for. I need just field name from a table, not the data. Thanks anyways.
 
I've used the ADOX object to get a table list before...

Something like this will work

<% Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open &quot;Some connection String&quot;
set objCat = Server.CreateObject(&quot;ADOX.Catalog&quot;)
objCat.ActiveConnection = objConn
For Each strTable In objCat.Tables
Response.Write strTable.Name & VBCrLf
Next
Set objCat = Nothing
objConn.Close
Set objConn = Nothing %>

Here's a field list of a table....

Set objConn = Server.CreateObject(&quot;ADODB.Connection&quot;)
objConn.Open &quot;Some connection String&quot;
Set objCatalog = Server.CreateObject(&quot;ADOX.Catalog&quot;)
objCatalog.ActiveConnection = objConn
dim strProperty
For Each strTable in objCatalog.Tables
If strTable.Name = &quot;a table&quot; Then
If strTable.Columns.Count > 0 Then
For Each strColumn In strTable.Columns
Response.Write strColumn.Name
Next
Else
Response.Write &quot;No fields currently in this table&quot;
End If
End If
Next
Set objRS = nothing
Set objCatalog = nothing
objConn.Close
Set objConn = nothing

 
Now, that's what exactly what I'm looking for.
Thanks a bunch.
 
I'm using &quot;strColumn.Type&quot; to get field's datatype. Instead of datatype, I'm getting numeric values. Do you know how to get datatype?

Thanks.
 
Yeah... The types are in the adovbs.inc constants file. You can look them up that way.
 
Quick way for field names...

create an rs

For Each fld In myRs.Fields
Response.Write fld.Name & &quot;<br />
Next
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top