João Pinto
João Pinto

Reputation: 1998

How can I open an access database in c#?

I'm trying to open an access database with the extension .accdb so I can read some information from this database. I have no problem doing this, if I use the wizard:

enter image description here

enter image description here

enter image description here

enter image description here

However when try to use code to do this I always get an exception when I try to connect: enter image description here

enter image description here

From debugging I understood that the exception comes from not having opened the connection. So I open the connection but the the database comes as empty:

enter image description here

I have looked around stack overflow and tried to apply many of the answers to similar questions but they haven't worked. In theory if I can connect through the wizard I should also be able to connect through OleDBConnection object in C#. How can I fix this?

Upvotes: 0

Views: 141

Answers (1)

João Pinto
João Pinto

Reputation: 1998

I found the problem. My table name had a space between "Tab_Project Data" and because I didn't use [] it was looking for a table named "Tab_Project" which it couldn't find. So I just had to put "[Tab_Project Data]" inside my query and now it works.

Upvotes: 1

Related Questions