[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2001-07-24
6
Medium Priority
?
498 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 54

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
Independent Software Vendors: 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 3

Accepted Solution

by:
jetforce earned 180 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

834 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