• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 216
  • Last Modified:

Access database from within C++

I am doing a school project. The project has to do several things such as customer management, project management, employee management, billing, etc. Together with my partner I decided we want to use an MS Access database for this. We can use any database engine we like, such as MS SQL, MySQL, etc. But because the project isn't that complicated and doesn't require a high performance database we decided to go with Access. However, I have no clue on how I can access the database WITHOUT using ODBC. The project is written using Microsoft Visual C++ 6 using pure Win32(NO MFC).

Anyone has an idea what we should use?

2 Solutions
Any reason why you can't use ODBC or ADO?

If you can't use ODBC or ADO, you should use SQL, it is simple enough:

Get connection to the database then send in a string of something like:

"SELECT foo, bar, baz FROM my_table
WHERE foo >= "blah blah blah" AND bar < 20"

You also pass pointers to variables that are to store the data received from the DB. Not sure about Access' exact syntax and how to specify it but I am sure that Access help files will tell you how.

The string is most likely passed in a two phase manner where you first pass the string and Access compiles it and return you a handle to the compiled query string. You then 'execute' that compiled query to perform it.

If you want to insert elements into the database you use INSERT instead of SELECT. In any case, the syntax of Access' SQL is also documented by microsoft in specific help files.

Note that access is a small database compared to other bigger databases so there are probably limitations to how advanced the query can be etc. However, for your simple application I doubt you will run into those kind of problems.

Is there any particular reason why you can't use ADO or ODBC?

ToolmakerAuthor Commented:
I never mentioned not using ADO. The general idea is using SQL strings to execute all the commands on the Access database. I prefer not to use MFC since my MFC knowledge is zero and I've heard the entire MFC interface is crap. Is the entire ADO thing MFC based? I have used DAO in Visual Basic before but DAO is obsolete now and I need to use C++.

ADO is MFC based as far as I know but ADO.NET is not. However, ADO.NET is .NET based so it require .NET framework.

However, when I say that ADO is MFC based it is perhaps not quite true. You can use it with MFC and visual studio is sort of geared up towards that. I believe though, that ADO can be used without dragging too much of other MFC stuff into the picture.

In this case I would suggest you look at ADO and if you have .NET framework you might want to check up on ADO.NET in that case you might even wanna check up on C# but C++ can also be used.

You can use ADO also from C++.
See http://www.codeguru.com/mfc_database/daoarticle.html
for example.
No comment has been added lately, so it's time to clean up this TA. I will
leave a recommendation in the Cleanup topic area that this question is:

Answered: Points split between Salte and rkupka

Please leave any comments here within the next seven days.

Experts: Silence means you don't care. Grading recommendations are made in light
of the posted grading guidlines (http://www.experts-exchange.com/help.jsp#hi73).


-bcl (bcladd)
EE Cleanup Volunteer
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now