如何在 PowerShell 中访问 DAO 枚举常量?

How to access DAO enumeration constants in PowerShell?

在 PowerShell 中,如何访问 DAO 枚举常量,例如 RecordsetTypeEnum dbOpenTable (1) 或 DataTypeEnum adVarNumeric (139)?现在,我只是将它们作为幻数放入,但引用适当的常量会更清晰、更容易阅读。

您可以使用所需的名称定义自定义 enum 类型:

enum DAODataType {
    adBigInt             = 0x14
    adBinary             = 0x80
    adBoolean            = 0x0B
    adBSTR               = 0x08
    adChapter            = 0x88
    adChar               = 0x81
    adCurrency           = 0x06
    adDate               = 0x07
    adDBDate             = 0x85
    adDBTime             = 0x86
    adDBTimeStamp        = 0x87
    adDecimal            = 0x0E
    adDouble             = 0x05
    adEmpty              = 0x00
    adError              = 0x0A
    adFileTime           = 0x40
    adGUID               = 0x48
    adIDispatch          = 0x09
    adInteger            = 0x03
    adIUnknown           = 0x0D
    adLongVarBinary      = 0xCD
    adLongVarChar        = 0xC9
    adLongVarWChar       = 0xCB
    adNumeric            = 0x83
    adPropVariant        = 0x8A
    adSingle             = 0x04
    adSmallInt           = 0x02
    adTinyInt            = 0x10
    adUnsignedBigInt     = 0x15
    adUnsignedInt        = 0x13
    adUnsignedSmallInt   = 0x12
    adUnsignedTinyInt    = 0x11
    adUserDefined        = 0x84
    adVarBinary          = 0xCC
    adVarChar            = 0xC8
    adVariant            = 0x0C
    adVarNumeric         = 0x8B
    adVarWChar           = 0xCA
    adWChar              = 0x82
}

然后传递 [DAODataType]::adVarNumeric 而不是 139

对于 RecordsetTypeEnum dbOpenTable(来自 Access),您可以使用:

[Reflection.Assembly]::LoadWithPartialName("Microsoft.Office.Interop.Access.Dao") | Out-null
[int][Microsoft.Office.Interop.Access.Dao.RecordsetTypeEnum]::dbOpenTable

对于 DataTypeEnum adVarNumeric(来自 ADODB,而非 Access),您可以使用:

[Reflection.Assembly]::LoadWithPartialName("ADODB") | Out-null
[int][ADODB.DataTypeEnum]::adVarNumeric