balasundaram
asked on
Regarding MFC database
I already created an Consoled based application(consider prj1) using AppWizard. So that my project contains only prj.cpp,prj.h,StdAfx.cpp and StdAfx.h these files.
Now I wanted to connect to ACCESS DATABASE from my project and take some values from various tables in the database and assign it to some variables. Please inform me ASAP How can Connect and Open the database with my present project(it doesn't contain any recordset..). So what header files I have to include and to connect to the database.
Now I wanted to connect to ACCESS DATABASE from my project and take some values from various tables in the database and assign it to some variables. Please inform me ASAP How can Connect and Open the database with my present project(it doesn't contain any recordset..). So what header files I have to include and to connect to the database.
You'll need to
#include <afxdb.h>
in your stdafx.h for anything to compile!
And like RAVID says, you can use Class Wizard to do the rest.
If you are reading from multiple tables (that are not joined) then you are better off creating a CDatabase object and using that to connect to the database. You can pass this database into the constructors for the CRecordsets that class wizard will generate for you.
If you want to read joined tables then the simplest way to do that is to create a Query in Access that does the join and then base the CRecordset on the query rather than the table.
There's lots of VC++ Help on this kind of stuff so you shouldn't have too many worries.
Good Luck, Carl.
#include <afxdb.h>
in your stdafx.h for anything to compile!
And like RAVID says, you can use Class Wizard to do the rest.
If you are reading from multiple tables (that are not joined) then you are better off creating a CDatabase object and using that to connect to the database. You can pass this database into the constructors for the CRecordsets that class wizard will generate for you.
If you want to read joined tables then the simplest way to do that is to create a Query in Access that does the join and then base the CRecordset on the query rather than the table.
There's lots of VC++ Help on this kind of stuff so you shouldn't have too many worries.
Good Luck, Carl.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Dear V_Bapat,
I can understand ur idea? But it will be useful if u send some sample program.
my mail-id is sbala12@yahoo.com
rgds
balaji
I can understand ur idea? But it will be useful if u send some sample program.
my mail-id is sbala12@yahoo.com
rgds
balaji
ASKER
Dear V_Bapat,
I can understand ur idea? But it will be useful if u send some sample program.
my mail-id is sbala12@yahoo.com
rgds
balaji
I can understand ur idea? But it will be useful if u send some sample program.
my mail-id is sbala12@yahoo.com
rgds
balaji
ASKER
Dear V_Bapat,
I can understand ur idea? But it will be useful if u send some sample program.
my mail-id is sbala12@yahoo.com
rgds
balaji
I can understand ur idea? But it will be useful if u send some sample program.
my mail-id is sbala12@yahoo.com
rgds
balaji
Hi Bala
I will send you some sample in a couple of hours as I am not on the PC where the code is.
In the meanwhile, you can have a look at the MSDN sample Daotable and Daoview. You will get a clearer picture.
Vicky
I will send you some sample in a couple of hours as I am not on the PC where the code is.
In the meanwhile, you can have a look at the MSDN sample Daotable and Daoview. You will get a clearer picture.
Vicky
configure a DSN for the database u want to use say myDSN.
now add a new class from the class wizard derive it from CRecordSet at this time u will be asked to the DSN give the DSN as myDSN.
now u will be able to access whatever u want.
hope this helps u
cheers