原创 使用ADOX方便的查询表和字段收藏

新一篇: 激活程序的disabled的按钮 | 旧一篇: INET控件的几点使用

测试环境:WINXP+VB6

添加2个列表框,1个按钮

 

'引用微软 ADO Ext.2.X for dll and Security

Dim cat As ADOX.Catalog

Dim cnn As ADODB.Connection

Dim tbl As ADOX.Table

 

Private Sub Command1_Click()

On Error Resume Next

For Each tbl In cat.Tables

'如果是sqlserver数据库,则变成If Left(tbl.Name, 3) <> "sys"

If Left(tbl.Name, 4) <> "MSys" Then

List1.AddItem tbl.Name

End If

Next

End Sub

 

Private Sub Form_Load()

Set cnn = New ADODB.Connection

Set cat = New ADOX.Catalog

cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\csdn_vb\database\article.mdb"

'cnn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=northwind;Data Source=yang"

Set cat.ActiveConnection = cnn

End Sub

 

Private Sub Form_Unload(Cancel As Integer)

Set cat = Nothing

Set con = Nothing

End Sub

 

Private Sub List1_Click()

Dim fld

Dim intfield As Integer

List2.Clear

intfield = cat.Tables(List1.List(List1.ListIndex)).Columns.Count

For i = 0 To intfield - 1

    Set fld = cat.Tables(List1.List(List1.ListIndex)).Columns(i)

    List2.AddItem fld.Name & " " & fld.Type & " " & fld.DefinedSize

Next

End Sub

发表于 @ 2004年09月08日 23:27:00|评论(loading...)|编辑

新一篇: 激活程序的disabled的按钮 | 旧一篇: INET控件的几点使用

评论

#Sunlight 发表于2006-04-01 13:21:00  IP: 210.186.252.*
With DAO, the TableDef object represents an able in the database and the TableDefs collection contains a TableDef object for each table in the database. This is similar to ADO, in which the Table object represents a table and the Tables collection contains all the tables.
However, unlike DAO, the ADO Tables collection may contain Table objects that aren't actual tables in your Microsoft Jet database. For example, row-returning, non-parameterized Microsoft Jet queries (considered Views in ADO) are also included in the Tables collection. To determine whether or not the Table object represents a table in the database, use the Type property. The following table lists the possible values for the Type property when using ADO with the Microsoft Jet Provider.

Type Description
1.ACCESS TABLE The Table is a Microsoft Access system table.
2.LINK The Table is a linked table from a non-ODBC data source.
3.PASS-THROUGH The Table is a linked table from an ODBC data source.
4.SYSTEM TABLE The Table is a Microsoft Jet system table.
5.TABLE The Table is a table.
6.VIEW The Table is a row-returning, non-parameterized query.

You should check the Table type at first.

Private Sub Command1_Click()

On Error Resume Next

For Each tbl In cat.Tables

'If Left(tbl.Name, 4) <> "MSys" Then
If tbl.Type = "TABLE" Then

List1.AddItem tbl.Name

End If
Debug.Prin
发表评论  


当前用户设置只有注册用户才能发表评论。如果你没有登录,请点击登录
Csdn Blog version 3.1a
Copyright © 龙卷风.NET