C++ Console Application with Access Database Data


MPD78
10-27-2009, 07:58 AM
Hello all,

Is it possible to link/import data stored in an Access database (2000 Version) to a C++ console application? If so, can you provide a simple example of how to code it?

I have done this before using VB Express through use of the database tools in the IDE, in a Windows Forms application and it worked fine. However, no coding on my part was required since I used the database tools provided by the IDE.

Here is an outline of what I want to be able to do.

I have thermal diffusivity values stored in the Access database in a data table. This property is just a function of temperature for my application.

I have 52 different materials that all have different thermal diffusivity values.

The C++ console app. prompts the user the enter a number corresponding to the appropriate material and then prompts the user to enter the temperature.

The data in the Access database is interpolated (linearly) based on the user selected material and user entered temperature.

The interpolated value is returned.


Basically, I am just being lazy, I can spend the rest of today entering in all of the values in arrays in C++ and performing the interpolation, but I am trying to be efficient and use the data that is already stored.

Any help would be greatly appreciated.

Thanks
Matt

MPD78
10-31-2009, 10:21 AM
I figured out how to do this with some help from a colleague of mine and this MSDN example.

http://msdn.microsoft.com/en-us/library/cc811599.aspx

You have to add 2 lines if you are using the ADO method.

The lines are

::CoInitialize(NULL); Add this line right below you main function() declaration statement.

::CoUnInitialize(); Add this line before the return 0; statement.

This method will work for .mdb file extensions as well as the .accdb file extensions for newer versions of Access.

Thanks
Matt

MPD78
11-18-2009, 02:19 PM
Also,

For connecting to an older Access Database such as, Access 2000, the above method does not work properly and the data types can be very problematic between C++ and Access.

A coworker of mine used this method and after some massaging of the data types it work just as desired.

http://www.cpp-home.com/tutorials/341_1.htm

Thanks
Matt