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

Table information without queries

Status
Not open for further replies.

vcherubini

Programmer
May 29, 2000
527
US
Hello.

I come from a PHP/Perl background and have recently been forced into using ASP at work. I am having a problem with getting information about a database so that I can work with it. Specifically, how do I find out the names of the tables in the database?

I am using Access. In PHP, I could VERY easily use code like so:
[tt]
<?php
mysql_connect(&quot;localhost&quot;, &quot;mysql_user&quot;, &quot;mysql_password&quot;);
$result = mysql_list_tables(&quot;mydb&quot;);

for ($i = 0; $i < mysql_num_rows($result); $i++)
printf (&quot;Table: %s\n&quot;, mysql_tablename($result, $i));

mysql_free_result($result);
?>
[/tt]
To get all of the names of the tables in a database. In ASP, I've found that to find the names of the fields, you have to query the database first, and then use the rs.Fields(num).Name function to get the names of the fields. However, if I try something like db_conn.Tables(0).Name, I get an error (where db_conn is the variable that holds the connection information to the database).

Thus, how do I get all of the names of each table in my database?

Thanks,
-Vic vic cherubini
krs-one@cnunited.com
 
Nevermind, I found the answer:

[tt]
<%

dim oConn, ors1
set oConn = Server.CreateObject(&quot;ADODB.connection&quot;)
oConn.Open &quot;DSN=dsn_here&quot;
set ors1 = oConn.OpenSchema(20)
ors1.movefirst
while not ors1.EOF
response.write(ors1(&quot;Table_Name&quot;) & &quot;<br />&quot;)
ors1.movenext
wend

%>
[/tt]

However, at the beginning, it spits out:
[tt]
MSysAccessObjects
MSysACEs
MSysObjects
MSysQueries
MSysRelationships
[/tt]

Is there a way for it to not display that? Or is that some crap that Access puts in the database that we don't know about?

Thanks. vic cherubini
krs-one@cnunited.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top