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

I've passed a table in the URL. How do I retrieve its fields?

Status
Not open for further replies.

gtubb

Programmer
Jan 15, 2004
24
GB
Hi

I have created a page which lists the tables in a database but hides the system tables.

The table names in the list are links which pass the table name to the page 'details.asp' with the following code:

<a href=&quot;details.asp?Table=<% = RS(&quot;TABLE_NAME&quot;) %>&quot;><% = RS(&quot;TABLE_NAME&quot;) %></a>

I want details.asp to list the fields in the table passed to it by the URL. Can anyone tell me what code I need to achieve that?

I'm tearing my hair out!

Many thanks.

Gerard

The full code of my page is below:


<%@Language=VBScript %>
<!-- #include file=&quot;adovbs.inc&quot;-->
<% Set conn = server.CreateObject(&quot;ADODB.Connection&quot;)
connectstring = &quot;Driver={Microsoft Access Driver (*.mdb)};&quot; &_
&quot;DBQ=&quot; & Server.MapPath(&quot;config/datasources/schooldoccategories.mdb&quot;)
conn.Open connectString

Set Rs = Conn.OpenSchema (adSchemaTables)
Do While Not Rs.EOF

Dim Hidesysfiles
Hidesysfiles = Rs (&quot;TABLE_NAME&quot;)
IF Hidesysfiles =&quot;MSysAccessObjects&quot; THEN
Response.Write &quot;&quot;
ELSEIF Hidesysfiles = &quot;MSysAccessXML&quot; THEN
Response.Write &quot;&quot;
ELSEIF Hidesysfiles = &quot;MSysACEs&quot; THEN
Response.Write &quot;&quot;
ELSEIF Hidesysfiles = &quot;MSysObjects&quot; THEN
Response.Write &quot;&quot;
ELSEIF Hidesysfiles = &quot;MSysQueries&quot; THEN
Response.Write &quot;&quot;
ELSEIF Hidesysfiles = &quot;MSysRelationships&quot; THEN
Response.Write &quot;&quot;
ELSE %><a href=&quot;details.asp?Table=<% = RS(&quot;TABLE_NAME&quot;) %>&quot;><% = RS(&quot;TABLE_NAME&quot;) %></a>
<% End If
Rs.MoveNext
Loop



%>
 
The simplest way to list the field names would be to select some data back from the recordset and loop through the fields collection, something like:
Code:
Dim sql_fields
'this will pull back a single record from the passed table name
'   I limited it to one record to cut down on communications time
sql_fields = &quot;SELECT TOP 1 * FROM &quot; & Request.QueryString(&quot;Table&quot;)

'assumed RS and Conn were already declared and setup
Set RS = Conn.Execute(sql_fields)

Dim fld
If RS.EOF Then
   Response.Write &quot;The table <i>&quot; & Request.QueryString(&quot;Table&quot;) & &quot;</i> does not appear to be a valid choice.&quot;
   Response.End
Else
   Response.Write &quot;Table: &quot; & Request.QueryString(&quot;Table&quot;)
End If

For Each fld in RS.Fields
   Response.Write fld.Name & &quot;<br>&quot;
Next

If you want more specialized information on each field you wil have to do some research on what SQL vocabulary is supported by MS Access. I'm not sure if you can do a direct query for Field information from Access like you can full scale db's, but it may just be something I haven't run into yet.

-T

01000111 01101111 01110100 00100000 01000011 01101111 01100110 01100110 01100101 01100101 00111111
The never-completed website:
 
Thank you for that. When I've spent some time working through your suggestions I'll let you know whether I can make it work.

Regards

Gerard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top