shaggy_the_sheep
asked on
Retrieve list of tables within MS Access Database
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
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
ASKER
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
A simple example would be great please, as i havent a clue where to start :-)
Cheers
Richard
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
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 .Connectio n")
Cnxn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../music/_ private/mu sicfiles.m db")
Set rstSchema = Cnxn.OpenSchema(adSchemaTa bles)
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(adSchemaTa bles)
Any ideas?
Thanks
Richard
<%
'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
Cnxn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("../music/_
Set rstSchema = Cnxn.OpenSchema(adSchemaTa
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(adSchemaTa
Any ideas?
Thanks
Richard
Have you declared the constant adSchemaTables ?
Otherwise this is where Option Explicit comes in handy :)
ASKER
No i dont think i have declared it...where would i need to insert?
Thanks
Richard
Thanks
Richard
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.
Const adSchemaTables = 20
Or as a lot of ASP developers do, just add all the ADO constants using the include file ADOVBS.inc.
ASKER
Easy when you know how!! :-)
Thanks very much
Richard
Thanks very much
Richard
A. Query the system tables: MSysObjects
B. (Better approach) Is to use the Connection's OpenSchema method.