Solved

how to get table names of a database  from an ado connection string

Posted on 2001-07-24
6
452 Views
Last Modified: 2013-11-23
I want to get the entire details of a database from an ado connection string. Like table name, field names,
queries etc. I am getting the data base name from the connection string. But i want to get the table names from it without using a dao reference.
0
Comment
Question by:pratheesh
6 Comments
 
LVL 50

Expert Comment

by:Ryan Chong
ID: 6311945
Hi pratheesh,

Retreive ALL the information about Access Table & Fields using ADO:

http://www.vbcode.com/asp/showsn.asp?theID=688

'Hope will help.
0
 
LVL 3

Expert Comment

by:jetforce
ID: 6311956
There is two ways, the first is using ADOX, you need to select the reference. This really only works well from Access Databases.
 The second is using the open schema method from the Connection object. The method/function returns a recordset.

The following returns all the tables for a connection, you can change it retrieve views/queries as well.
 Set recScheme = connDB.OpenSchema(adSchemaTables, Array(Empty, Empty, Empty, "TABLE"))


This will return all the fields for a table

Set recTable = connDB.OpenSchema(adSchemaColumns, Array(Empty, Empty, Trim$(recScheme("Table_Name"))))


Hope this helps, you can find more about this function in the MSDN Help files.


PodgeMaster
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 6311965
Jetforce, you are not new to EE so should be aware of the guidelines on comments vs answers. Please re-read this at the bottom of this page and do not post "answers" in this way in future. If you continue to do so your account will be referred to customer services.

If you have opened the connection the following example shows how you can obtain the table names and table types from the database. In this case an access database but that is only limited by your connection string properties so if you are using SQL Server then the appropriate connection string would give you the same sort of results.

Dim cnn As ADODB.Connection
Dim rst As ADODB.Recordset
Dim strMessage As String
Set cnn = New ADODB.Connection
Set rst = New ADODB.Recordset
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\testbed\cremosa2k.mdb;"
cnn.Open
Set rst = cnn.OpenSchema(adSchemaTables)
With rst
  .MoveFirst
  Do
    strMessage = strMessage & rst.Fields("TABLE_NAME").Value & " : " & rst.Fields("TABLE_TYPE").Value & vbLf
    .MoveNext
  Loop Until .EOF
End With
MsgBox strMessage
rst.Close
cnn.Close
Set rst = Nothing
Set cnn = Nothing

   
0
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 3

Accepted Solution

by:
jetforce earned 60 total points
ID: 6312097
Sorry TimCottee,
 but when I posted the answer, there was no reply, if you look at the times of the two posts. They are only a minute apart. It took me more than a minute to write the answer. It was just coincidince in my choice of wording.
If pratheesh wants to reject my answer and award the points
to ryancys, that is fine.
Jetforce
0
 
LVL 2

Expert Comment

by:Lunchy
ID: 6319429
Hi jetforce,

I'm rejecting your answer as it duplicates the information posted by ryancys.

>but when I posted the answer, there was no reply, if you look at the times of the two posts.

This is one of the reasons why it is the etiquette here in VB to *always* post comments.  This topic area is very busy, and it is not unusual to see three or four nearly simultaneous comments all with the correct answer.

Lunchy
Friendly Neighbourhood Community Support Moderator
0
 

Author Comment

by:pratheesh
ID: 6321737
thanks jetforce for your immediate action
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

786 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