How do you get a list of MS Access data types?

2019-09-06 03:12发布

问题:

I am trying to list data types from Microsoft Access 2000-2007 (depending on the MS Access database version) in a combobox for a C# program. How can I achieve such a thing?

回答1:

I don't think it is possible to interrogate the engine at run time to enumerate the data types it supports. For example, DAO will not reveal some of the Jet 4.0 data types such as NCHAR and BINARY; ADO will reveals data types that the Access database engine has never supported; only ACEDAO will reveal multivalued types.

I think you need to know in advance the data types each version of the engine supports then select the appropriate set at run time.

Jet 4.0 data types (Access2000 to 2003 inclusive) and the various synonyms can be found here (should also give some hints about which types are new to Jet 4.0, just in case you need to support earlier versions of the engine).

ACE (Access2007) added an Attachment type; also multivalued ("complex") types in order to support SharePoint lists: I think you will need to decide for yourself whether multivalued types are distinct types or merely variations on existing types. There are some details in the Access2007 Help.



回答2:

Microsoft.Office.Interop.Access.Dao.DataTypeEnum

Of course, you'll need to add a reference, and I absolutely hate adding reference to Office because you get tied to a version of Office,and I hate updating code every time we upgrade.