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()
[AHK]遍历access表名
最新推荐文章于 2024-03-19 22:10:15 发布