Dim db1 As Database
Set db1 = DBEngine.OpenDatabase(数据库文件全路径)
Dim Tables As TableDef, fld
For Each Tables In db.TableDefs
If Left(Tables.Name, 4) <>"MSys" Then Print Tables.Name
Next Tables
db.Close
Set db = Nothing
连数据库会了吧?连上后用下面的语句写。tsql = "select name from sysobjects where type='U'"
rs.Open tsql, cn, 1, 1
Do Until rs.EOF
list1.AddItem rs.Fields("name")
rs.MoveNext
Loop
//C#获取Access数据库中的所有表名和列名string ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0" + @"Data Source=E:\report20100819\report20100819.mdb"
OleDbConnection Conn = new OleDbConnection(ConnectionString)
Conn.Open()
DataTable shemaTable = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" })
foreach (DataRow dr in shemaTable.Rows)
{
Console.WriteLine(dr["TABLE_NAME"])
DataTable columnTable = Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, dr["TABLE_NAME"].ToString(), null })
foreach (DataRow dr2 in columnTable.Rows)
{
Console.WriteLine(dr2["COLUMN_NAME"])
}
}
Conn.Close()
解释:
“Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Tables, new object[] { null, null, null, "TABLE" })”返回数据库中所有的数据表清单,返回值为DataTable。
“Conn.GetOleDbSchemaTable(OleDbSchemaGuid.Columns, new object[] { null, null, dr["TABLE_NAME"].ToString(), null })”返回指定数据表中所有的数据列清单,返回值为DataTable。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)