Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Retrieve list of tables within MS Access Database

Posted on 2006-07-09
9
Medium Priority
?
221 Views
Last Modified: 2008-02-01
Hi all

Is there a way using ASP and SQL to retrieve a list of all the tables contained within an MS Access Database?

Also is there another SQL query that will return all of the table fields, without returning any records?

Thanks in advance

Richard
0
Comment
Question by:shaggy_the_sheep
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 4
9 Comments
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068581
There are a couple of ways:
A.  Query the system tables: MSysObjects
B.  (Better approach) Is to use the Connection's OpenSchema method.
0
 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 17068592
Using the OpenSchema method does a schema have to have been specifically defined (or is it defined simply through creating tables, etc.)

A simple example would be great please, as i havent a clue where to start :-)

Cheers

Richard
0
 
LVL 75

Accepted Solution

by:
Anthony Perkins earned 2000 total points
ID: 17068604
Consider looking at the one in the MDAC Help :)

Here is a link:
OpenSchema Method Example (VB)
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthopenschemax.asp
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 17068632
Okay ive got this far...

<%

'BeginOpenSchemaVB

    'To integrate this code
    'replace the data source and initial catalog values
    'in the connection string

Public Sub Main()

    Dim Cnxn
    Dim rstSchema
    Dim strCnxn
       
      Set Cnxn = Server.CreateObject("ADODB.Connection")
      Cnxn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../music/_private/musicfiles.mdb")
      
    Set rstSchema = Cnxn.OpenSchema(adSchemaTables)
   
    Do Until rstSchema.EOF
        Response.Write "Table name: " & _
            rstSchema("TABLE_NAME") & vbCrLf & "Table type: " & rstSchema("TABLE_TYPE") & vbCrLf
        rstSchema.MoveNext
    Loop
   
    ' clean up
    rstSchema.Close
    Cnxn.Close
    Set rstSchema = Nothing
    Set Cnxn = Nothing
    Exit Sub

End Sub
'EndOpenSchemaVB

Main()

%>

But i am getting an error:

Object or provider is not capable of performing requested operation.
/edit/getTable.asp, line 18

Line 18 being: Set rstSchema = Cnxn.OpenSchema(adSchemaTables)

Any ideas?

Thanks

Richard
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068643
Have you declared the constant adSchemaTables ?
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068646
Otherwise this is where Option Explicit comes in handy :)
0
 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 17068647
No i dont think i have declared it...where would i need to insert?

Thanks

Richard
0
 
LVL 75

Expert Comment

by:Anthony Perkins
ID: 17068661
It is as simple as adding the following at the start of your code:
Const adSchemaTables = 20

Or as a lot of ASP developers do, just add all the ADO constants using the include file ADOVBS.inc.
0
 
LVL 5

Author Comment

by:shaggy_the_sheep
ID: 17068671
Easy when you know how!! :-)

Thanks very much

Richard
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

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…
I was asked about the differences between classic ASP and ASP.NET, so let me put them down here, for reference: Let's make the introductions... Classic ASP was launched by Microsoft in 1998 and dynamically generate web pages upon user interact…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…
Want to learn how to record your desktop screen without having to use an outside camera. Click on this video and learn how to use the cool google extension called "Screencastify"! Step 1: Open a new google tab Step 2: Go to the left hand upper corn…

609 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