[AHK]遍历access表名

sDatabaseName :=  A_ScriptDir . "\TestDatabase.accdb"
adOpenStatic :=   3, adLockOptimistic :=   3, adUseClient :=   3
adSchemaTables := 20
sConnectionString :=   "provider=Microsoft.ACE.OLEDB.12.0;Data Source=" . sDatabaseName

oCatalog :=   ComObjCreate("ADOX.Catalog")
oConnection :=   ComObjCreate("ADODB.Connection")



IfnotExist, %sDatabaseName%
{
	oCatalog.Create(sConnectionString)
	oTable :=   ComObjCreate("ADOX.Table")
	oTable.Name :=   "MyTable"
	oTable.Columns.Append("ID", 3)   ; adInteger 3 Indicates a four-byte signed integer (DBTYPE_I4). 
	oTable.Columns.Append("Name", 202, 50)   ; adVarWChar 202 Indicates a null-terminated Unicode character string. 
	oCatalog.Tables.Append(oTable)

}

oConnection.Open(sConnectionString)
oCatalog.ActiveConnection := oConnection
   
   
   
;遍历表的名称
oRecordset:=oConnection.OpenSchema(adSchemaTables)
 Loop 
 {
     if oRecordset.Fields["TABLE_TYPE"].Value="Table"
     {
           MsgBox, %   "TABLE Name: " oRecordset.Fields["TABLE_NAME"].Value "`n"
       . "TABLE_TYPE: " oRecordset.Fields["TABLE_TYPE"].Value

     }
     oRecordset.MoveNext
 }until oRecordset.EOF

   
oTable :=   ""
oCatalog :=   ""
; Disconnect the connection
oRecordset.Close(), oConnection.Close()

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值