views:

407

answers:

3

Hello! 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?

+2  A: 

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.

David Stratton
Thanks, I'll look into it!
Partial
DAO will only give you the pre-Access2000 data types plus DECIMAL (but not the scale and precision values), won't give you e.g. NCHAR and BINARY data types from Jet 4.0 (Access2000 onwards) or multi-value types (Access2007 onwards).
onedaywhen
Can't DAO be used with late binding, which would mean you wouldn't need a reference? Secondly, if you're working with files created in both Access 2007 and with earlier versions, you'll need DAO-version-specific checks, since DAO 3.6 (Jet 4.0, or Access 2000, 2002 and 2003) was superseded by the Jet/ACE-specific DAO version that shipped with Access 2007 and added some new data types (not very useful ones -- mostly for Sharepoint compatibility).
David-W-Fenton
"Can't DAO be used with late binding" -- no. DAO 3.6 will not reveal NCHAR and binary data types.
onedaywhen
+1  A: 

There are some lists and refrences here http://wiki.lessthandot.com/index.php/Determine_Field_Type that may help.

Remou
The examples are in Visual Basic :S
Partial
+2  A: 

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.

onedaywhen
So what you are saying is that I should add a reference to ACEDAO and use that?
Partial
Can I use ACEDAO with MS Access 2000-2003 or is that only for MS Access 2007?
Partial