The .NET Developer Community
Sign in
|
Join
|
Help
Home
Blogs
Forums
FAQ
Wikis
Members
Search
Services
Forums
»
Archived Forums
»
VB6 & Databases
»
How to Use Visual Basic's ADOX to determine if internal database objects exist
How to Use Visual Basic's ADOX to determine if internal database objects exist
rated by 0 users
This post has 0 Replies | 1 Follower
paCkeTroUTer
Melbourne, Australia
Since 10/5/2002
Posts
581
Reputation
5,785
Reply
Jeffery Fernandez
(
paCkeTroUTer
)
Posted: 12/17/2002 6:00 PM
rated by 0 users
Using Visual Basic's ADOX to determine if internal database objects exist
Soon after ADO's release, Microsoft created an extension to the object library called ActiveX Data Objects Extensions, or ADOX. This library includes most of the DAO features missing from standard ADO, including objects related to a database's schema. With ADOX you can easily determine if a database contains a specific table, view, or query.
To do so, set a reference to
Microsoft ADO Ext. 2.x for DDL and Security
. For schema purposes, the ADOX consists of a Catalog object, which contains the object collections that describe the database, tables and views among them. To test for an existing table in the Tables collection, you can either iterate through the collection and check each item's name against the test string; or you can use the following method, as seen in the following code:
Place a command button on a form and put the following code in the code editor.
Code:
Private Sub Command1_Click()
Dim cat As ADOX.Catalog
Dim tbl As ADOX.Table
Dim con As New ADODB.Connection
con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & "C:\Program Files\Microsoft Visual Studio\VB98\Biblio.mdb"
con.Open
Set cat = New ADOX.Catalog
Set cat.ActiveConnection = con
On Error Resume Next
Set tbl = cat.Tables("Address")
If tbl Is Nothing Then
MsgBox "MyTable doesn't exist"
Else
MsgBox "MyTable exists"
Set tbl = Nothing
End If
End Sub
A VB turned PHP geek
Filed under:
FAQ
,
MS Office
| Post Points: 5
< Previous Topic
|
Next Topic >
Page 1 of 1 (1 items) |
RSS
Copyright 1998-2017 vbCity.com LLC