Connecting C++ to Microsoft Access

10 pts.
Tags:
C
Microsoft Access
Microsoft Visual Studio
How do you connect Visual c++ to the Microsoft Access database?

Software/Hardware used:
visual studio 2005 on vista (dell machine)

Answer Wiki

Thanks. We'll let you know when a new response is added.

1. I’m not a C++ developer, but I think I can answer this question. You need to use ODBC drivers.

At the beginning of your file, include:

#include "sql.h"
#include "sqlext.h"

Then in your appropriate function:

SQLRETURN ret;
SQLHDBC dbc; /* assume already allocated */

ret = SQLDriverConnect(dbc, NULL, "DSN=mydsn;", SQL_NTS,
NULL, 0, NULL, SQL_DRIVER_COMPLETE);

(Reference: ODBC from C Tutorial Part 1)

In order for all this to work you need to configure the access database as a data store in odbc. You can do this by going to Administrative tools in control panel and opening data sources(ODBC)

What you do with the ret variable is a bit past me, I always did by Access UI using Visual Basic. That language has a lot more intuitive access to the odbc store.

——————–

Take a look at these similar questions:

-CarlosDL

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

Thanks! We'll email you when relevant content is added and updated.

Following

Share this item with your network: