Manipulating Access databases with C++

C

cplxphil

Hello all,

I need to use a free compiler (specifically Bloodshed's Dev C++
compiler) to manipulate an Access database. I have found a tutorial
on how to use Microsoft Visual C++ with Access, but I need to know the
simplest way to use queries from Dev C++. All that I need to do is
write queries from the program, alter the database, and save data to
an array from the database. The more simple I can keep things, the
better.

Any help anyone can provide would be greatly appreciated.

Sincerely,
Phil
 
A

Albert D. Kallal

the DAO object model + the jet database engine has shipped with every
copy of windows since windows 98 I believe.

So you do NOT need to install any software to open, read, modify a access
"mdb" file.

the DAO object model is a simple com object that you can use.

For example, if you take a pure clean windows xp box with NO software, the
following
windows script can be run (just paste the below into notepad, rename the
file
extension as .vbs, and you have your first windows script!).

Set dbeng = CreateObject("DAO.DBEngine.36")
strMdbFile = "C:\Documents and Settings\Albert\My
Documents\Access\multiselect\MultiSelect.mdb"
Set db = dbeng.OpenDatabase(strMdbFile)
set rstContacts = db.OpenrecordSet("select * from contacts with city =
'Edmonton'")
rstContacts.MoveLast
msgbox "there is " & rstContacts.RecordCount & " records in the table
contacts"
rstContacts.Close
db.Close


So, if you have a compiler..then all you need is to set a reference to the
dao object that ships with windows xp etc.

As the above shows, you could read/write/open the mdb file without any
software having yet been installed. the above example uses notepad that
ships with windows and then you simply save the file as a windows script.
Double click on the above script...and it will run and then open the access
file....

So, you don't need to purchase, or even install anything on your computer,
the ability to read that mdb file is shippsed with the windows system...
 
C

cplxphil

the DAO object model + the jet database engine has shipped with every
copy of windows since windows 98 I believe.

So you do NOT need to install any software to open, read, modify a access
"mdb" file.

the DAO object model is a simple com object that you can use.

For example, if you take a pure clean windows xp box with NO software, the
following
windows script can be run (just paste the below into notepad, rename the
file
extension as .vbs, and you have your first windows script!).

Set dbeng = CreateObject("DAO.DBEngine.36")
strMdbFile = "C:\Documents and Settings\Albert\My
Documents\Access\multiselect\MultiSelect.mdb"
Set db = dbeng.OpenDatabase(strMdbFile)
set rstContacts = db.OpenrecordSet("select * from contacts with city =
'Edmonton'")
rstContacts.MoveLast
msgbox "there is " & rstContacts.RecordCount & " records in the table
contacts"
rstContacts.Close
db.Close

So, if you have a compiler..then all you need is to set a reference to the
dao object that ships with windows xp etc.

As the above shows, you could read/write/open the mdb file without any
software having yet been installed. the above example uses notepad that
ships with windows and then you simply save the file as a windows script.
Double click on the above script...and it will run and then open the access
file....

So, you don't need to purchase, or even install anything on your computer,
the ability to read that mdb file is shippsed with the windows system...


OK, thank you very much for the tip.

How exactly would you access the .vbs file from C++? Or is there some
way to query the database directly from C++?

I guess my issue is that I need to query the Access database as part
of a program.

-Phil
 
A

Albert D. Kallal

OK, thank you very much for the tip.
How exactly would you access the .vbs file from C++? Or is there some
way to query the database directly from C++?

You can't query sql server, or Excel, or word form c++. You have to use an
"library" or "com object" to accomplish that goal.

(that is what I did with the vbs script).

In your cause, you need to create an instance of the dao "object" in c++.
How you create instances of objects in c++ I simple don't know.

The process for using a com object in windows scripting, VB, VBA, c++,
Delphi, FoxPro or <insert your favorite language> here will thus vary
depending on your language. Any Delphi, FoxPro, VB, VBA developer etc.
should be able to take the above script and be off and running with the
example...

So, assuming your language of choice allows one to create an instance of
that object, then you should be off and running...

I don't know how object library and instances of objects are handled in c++.
I can assume that anyone who writes c++ would know this (other wise how can
you write anything at all of use in a windows environment?).

About the only issue here would be if you early, or late binding in c++

There is an example of using the DAO .dll library here:
http://www.codeproject.com/KB/database/cppdao.aspx

Using the above DAO .dll library will allow you to execute any sql updates
on that mdb file.....
 
B

Brendan Reynolds

Hello all,

I need to use a free compiler (specifically Bloodshed's Dev C++
compiler) to manipulate an Access database. I have found a tutorial
on how to use Microsoft Visual C++ with Access, but I need to know the
simplest way to use queries from Dev C++.

While your development environment will be different, I would expect that
the code that actually reads from and writes to the database will probably
be similar if not identical in any implementation of the C++ language. But
you'd be more likely to get a definitive answer in a C++ forum.
 
C

cplxphil

While your development environment will be different, I would expect that
the code that actually reads from and writes to the database will probably
be similar if not identical in any implementation of the C++ language. But
you'd be more likely to get a definitive answer in a C++ forum.

Thank you everyone, I appreciate the information. I will post further
questions to the comp.lang.C++.moderated forum.

Again, I appreciated the help.

-Phil
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top