CONN.OPEN SET RS=CONN.EXECUTE("select name from sysobjects where xtype='U'")'得到用户表 DO WHILE NOT RS.EOF LIST1.ADDITEM RS(0) SET RS1=CONN.EXECUTE("SELECT Name FROM syscolumns WHERE id = OBJECT_ID(N'"& rs(0) &" ') ")‘得到表中的所有字段 do while not rs1.eof list2.additem rs1(0) loop loop 这个方法对ACCESS数据库无效
'两个ListBox: List1 , List2 '一个CommandButon Command1 Dim cnn As New ADODB.ConnectionPrivate Sub Command1_Click() '引用ADO对象库 '引用ADO Ext cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mis-yz\data1\DATA1.mdb;Persist Security Info=False" cnn.Open Dim Cat1 As New ADOX.Catalog Cat1.ActiveConnection = cnn Dim tbs As ADOX.Tables Set tbs = Cat1.Tables For Each tb In tbs List1.AddItem tb.Name Next End SubPrivate Sub Form_Load() Command1.Caption = "显示表名" End SubPrivate Sub List1_Click() On Error Resume Next Dim rst As New ADODB.Recordset tablename = List1.Text SQL = "select * from " & tablename rst.Open SQL, cnn, 3, 2 m = rst.Fields.Count List2.Clear For i = 1 To m List2.AddItem rst(i - 1).Name Next End Sub
SET RS=CONN.EXECUTE("select name from sysobjects where xtype='U'")'得到用户表
DO WHILE NOT RS.EOF
LIST1.ADDITEM RS(0)
SET RS1=CONN.EXECUTE("SELECT Name FROM syscolumns WHERE id = OBJECT_ID(N'"& rs(0) &" ') ")‘得到表中的所有字段
do while not rs1.eof
list2.additem rs1(0)
loop
loop
这个方法对ACCESS数据库无效
'一个CommandButon Command1
Dim cnn As New ADODB.ConnectionPrivate Sub Command1_Click()
'引用ADO对象库
'引用ADO Ext
cnn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=D:\mis-yz\data1\DATA1.mdb;Persist Security Info=False"
cnn.Open
Dim Cat1 As New ADOX.Catalog
Cat1.ActiveConnection = cnn
Dim tbs As ADOX.Tables
Set tbs = Cat1.Tables
For Each tb In tbs
List1.AddItem tb.Name
Next
End SubPrivate Sub Form_Load()
Command1.Caption = "显示表名"
End SubPrivate Sub List1_Click()
On Error Resume Next
Dim rst As New ADODB.Recordset
tablename = List1.Text
SQL = "select * from " & tablename
rst.Open SQL, cnn, 3, 2
m = rst.Fields.Count
List2.Clear
For i = 1 To m
List2.AddItem rst(i - 1).Name
Next
End Sub