views:

86

answers:

1

Hi,
How do I program against Access 2007 in C#? I don't see any VSTO templates for it. All I need to do is define a schema, let the user fill in the data on their own, and then read all of the data they entered back into my program. The reading part looks easy...how would I programmatically create a MS Access Database, and how would I hook up to know the user has closed the current database?

Thanks, Roy

+2  A: 

You'll need to create a reference to Microsoft ActiveX Data Objects and do some InterOp work. There's a post here that will get you started.

UPDATE

Apparently that post is a bit dated and does not include some details specific to Access 2007.

Using the JET provider will not work with the new accdb file format. You will need to use the 2007 Office System Driver - Data connectivity Components (you can download it from here).

As mentioned in a comment below, you'll have to change your connection string to use the following provider: Microsoft.ACE.OLEDB.12.0.

Jason Down
This only works against MDB files, which are from Access 2003 and below. Any idea on how to do this for accdb files, which are for Access 2007?
LPCRoy
Same approach, different OLE DB provider. You need Provider=Microsoft.ACE.OLEDB.12.0; and you probably need to remove ;Jet OLEDB:Engine Type=5.
onedaywhen
Awesome, Thanks!
LPCRoy