f



Database connection to MS Access & MS Foxpro

Hi,

When we select new project ,can "MFC AppWizard(exe)" make connection
to database ? or  only "database project" can make connection to
database ?

How do i make connection to database(MS Access/Foxpro) and perform sql
using MFC Appwizard(exe) with ODBC --CDatabase?
Any sample code ? 
Thanks.
0
cbtan
12/15/2003 9:34:46 AM
comp.windows.tools.mfc 1371 articles. 0 followers. Post Follow

9 Replies
1526 Views

Similar Articles

[PageSpeed] 43

CBTan wrote:

> Hi,
> 
> When we select new project ,can "MFC AppWizard(exe)" make connection
> to database ? or  only "database project" can make connection to
> database ?
> 
> How do i make connection to database(MS Access/Foxpro) and perform sql
> using MFC Appwizard(exe) with ODBC --CDatabase?
> Any sample code ? 
> Thanks.

Yes, an MFC application can connect to a database.  To use ODBC you must 
first define a DSN in the ODBC manager (in control panel).

See the ENROLL tutorial and program in the VC help.

-- 
Scott McPhillips [VC++ MVP]

0
Scott
12/15/2003 12:49:44 PM
You can create recordsets with classwizard.
use CRecordset for ODBC or CDoaRecordset for DAO as base class,
connect to the database, choice the table and update the fields.
Read also the book: Visual C++ 6 Database programming tutorial, Wendy
Sarrett

Theo Buys

CBTan <cbtan@pj.ebx.com> wrote in message
news:5cbd4cb8.0312150134.38bb4a89@posting.google.com...
> Hi,
>
> When we select new project ,can "MFC AppWizard(exe)" make connection
> to database ? or  only "database project" can make connection to
> database ?
>
> How do i make connection to database(MS Access/Foxpro) and perform sql
> using MFC Appwizard(exe) with ODBC --CDatabase?
> Any sample code ?
> Thanks.


0
Theo
2/9/2004 4:42:11 PM
DAO has been depreciated.  MS wants you to move to ADO.  Not too hard to
write wrapper classes to provide the same functionality as
CDaoDatabase/CDaoRecorset (etc).


--
-------------------------------------------------------------------------
Free software  - Baxter Codeworks  www.baxcode.com
-------------------------------------------------------------------------


"Theo Buys" <development@noiwal.nl> wrote in message
news:4027b973$0$1413$19deed1b@news.inter.NL.net...
> You can create recordsets with classwizard.
> use CRecordset for ODBC or CDoaRecordset for DAO as base class,
> connect to the database, choice the table and update the fields.
> Read also the book: Visual C++ 6 Database programming tutorial, Wendy
> Sarrett
>
> Theo Buys
>
> CBTan <cbtan@pj.ebx.com> wrote in message
> news:5cbd4cb8.0312150134.38bb4a89@posting.google.com...
> > Hi,
> >
> > When we select new project ,can "MFC AppWizard(exe)" make connection
> > to database ? or  only "database project" can make connection to
> > database ?
> >
> > How do i make connection to database(MS Access/Foxpro) and perform sql
> > using MFC Appwizard(exe) with ODBC --CDatabase?
> > Any sample code ?
> > Thanks.
>
>


0
Baxter
2/9/2004 5:07:15 PM
Not too hard? How do you create classes that the classwizard can pickup and
can update the records in your recordset when your database layout is
changed?


Baxter <lbax01.spamguard@baxcode.com> wrote in message
news:102ffi7t6s1b4b1@corp.supernews.com...
> DAO has been depreciated.  MS wants you to move to ADO.  Not too hard to
> write wrapper classes to provide the same functionality as
> CDaoDatabase/CDaoRecorset (etc).
>
>
> --
> -------------------------------------------------------------------------
> Free software  - Baxter Codeworks  www.baxcode.com
> -------------------------------------------------------------------------
>
>
> "Theo Buys" <development@noiwal.nl> wrote in message
> news:4027b973$0$1413$19deed1b@news.inter.NL.net...
> > You can create recordsets with classwizard.
> > use CRecordset for ODBC or CDoaRecordset for DAO as base class,
> > connect to the database, choice the table and update the fields.
> > Read also the book: Visual C++ 6 Database programming tutorial, Wendy
> > Sarrett
> >
> > Theo Buys
> >
> > CBTan <cbtan@pj.ebx.com> wrote in message
> > news:5cbd4cb8.0312150134.38bb4a89@posting.google.com...
> > > Hi,
> > >
> > > When we select new project ,can "MFC AppWizard(exe)" make connection
> > > to database ? or  only "database project" can make connection to
> > > database ?
> > >
> > > How do i make connection to database(MS Access/Foxpro) and perform sql
> > > using MFC Appwizard(exe) with ODBC --CDatabase?
> > > Any sample code ?
> > > Thanks.
> >
> >
>
>


0
Theo
2/11/2004 8:29:30 AM
I never had much luck with the ClassWizard *changing* a recordset class once
it was generated.  Any changes had to be hand done, or you had to delete and
regenerate the entire class.

I'm finding that direct field access is more practical - changes have less
impact on your code. Something like:
  if (rsTable1.GetIntValue(_T("Field1")) == 1) {
    // do something

In short, I wrapped the ADO so that I could access the values either
individually, or as members of a class.  I'm finding that copying all the
values into current memory as CDaoRecordset and CRecordset do is
unnecessary.  If I add a field/column, I don't have to touch existing code
(except for possible init of a new record)

--
-------------------------------------------------------------------------
Free software  - Baxter Codeworks  www.baxcode.com
-------------------------------------------------------------------------


"Theo Buys" <development@noiwal.nl> wrote in message
news:4029e8fd$0$1414$19deed1b@news.inter.NL.net...
> Not too hard? How do you create classes that the classwizard can pickup
and
> can update the records in your recordset when your database layout is
> changed?
>
>
> Baxter <lbax01.spamguard@baxcode.com> wrote in message
> news:102ffi7t6s1b4b1@corp.supernews.com...
> > DAO has been depreciated.  MS wants you to move to ADO.  Not too hard to
> > write wrapper classes to provide the same functionality as
> > CDaoDatabase/CDaoRecorset (etc).
> >
> >
> > "Theo Buys" <development@noiwal.nl> wrote in message
> > news:4027b973$0$1413$19deed1b@news.inter.NL.net...
> > > You can create recordsets with classwizard.
> > > use CRecordset for ODBC or CDoaRecordset for DAO as base class,
> > > connect to the database, choice the table and update the fields.
> > > Read also the book: Visual C++ 6 Database programming tutorial, Wendy
> > > Sarrett
> > >
> > > Theo Buys
> > >
> > > CBTan <cbtan@pj.ebx.com> wrote in message
> > > news:5cbd4cb8.0312150134.38bb4a89@posting.google.com...
> > > > Hi,
> > > >
> > > > When we select new project ,can "MFC AppWizard(exe)" make connection
> > > > to database ? or  only "database project" can make connection to
> > > > database ?
> > > >
> > > > How do i make connection to database(MS Access/Foxpro) and perform
sql
> > > > using MFC Appwizard(exe) with ODBC --CDatabase?
> > > > Any sample code ?
> > > > Thanks.
> > >
> > >
> >
> >
>
>


0
Baxter
2/11/2004 6:27:11 PM
Can your ADO wrapper classes replace my CDaoRecordset-s without lot of
recoding?
I have a lot of old projects (Dao and ODBC) here waiting for an update and
included a derived recordset which can randomize the data access without
redundancy.



Baxter <lbax01.spamguard@baxcode.com> wrote in message
news:102kt0l271ed5b3@corp.supernews.com...
> I never had much luck with the ClassWizard *changing* a recordset class
once
> it was generated.  Any changes had to be hand done, or you had to delete
and
> regenerate the entire class.
>
> I'm finding that direct field access is more practical - changes have less
> impact on your code. Something like:
>   if (rsTable1.GetIntValue(_T("Field1")) == 1) {
>     // do something
>
> In short, I wrapped the ADO so that I could access the values either
> individually, or as members of a class.  I'm finding that copying all the
> values into current memory as CDaoRecordset and CRecordset do is
> unnecessary.  If I add a field/column, I don't have to touch existing code
> (except for possible init of a new record)
>
> --
> -------------------------------------------------------------------------
> Free software  - Baxter Codeworks  www.baxcode.com
> -------------------------------------------------------------------------
>
>
> "Theo Buys" <development@noiwal.nl> wrote in message
> news:4029e8fd$0$1414$19deed1b@news.inter.NL.net...
> > Not too hard? How do you create classes that the classwizard can pickup
> and
> > can update the records in your recordset when your database layout is
> > changed?
> >
> >
> > Baxter <lbax01.spamguard@baxcode.com> wrote in message
> > news:102ffi7t6s1b4b1@corp.supernews.com...
> > > DAO has been depreciated.  MS wants you to move to ADO.  Not too hard
to
> > > write wrapper classes to provide the same functionality as
> > > CDaoDatabase/CDaoRecorset (etc).
> > >
> > >
> > > "Theo Buys" <development@noiwal.nl> wrote in message
> > > news:4027b973$0$1413$19deed1b@news.inter.NL.net...
> > > > You can create recordsets with classwizard.
> > > > use CRecordset for ODBC or CDoaRecordset for DAO as base class,
> > > > connect to the database, choice the table and update the fields.
> > > > Read also the book: Visual C++ 6 Database programming tutorial,
Wendy
> > > > Sarrett
> > > >
> > > > Theo Buys
> > > >
> > > > CBTan <cbtan@pj.ebx.com> wrote in message
> > > > news:5cbd4cb8.0312150134.38bb4a89@posting.google.com...
> > > > > Hi,
> > > > >
> > > > > When we select new project ,can "MFC AppWizard(exe)" make
connection
> > > > > to database ? or  only "database project" can make connection to
> > > > > database ?
> > > > >
> > > > > How do i make connection to database(MS Access/Foxpro) and perform
> sql
> > > > > using MFC Appwizard(exe) with ODBC --CDatabase?
> > > > > Any sample code ?
> > > > > Thanks.
> > > >
> > > >
> > >
> > >
> >
> >
>
>


0
Theo
2/12/2004 2:29:23 PM
--
-------------------------------------------------------------------------
Free software  - Baxter Codeworks  www.baxcode.com
-------------------------------------------------------------------------


"Theo Buys" <development@noiwal.nl> wrote in message
news:402b8ed6$0$280$19deed1b@news.inter.NL.net...
> Can your ADO wrapper classes replace my CDaoRecordset-s without lot of
> recoding?

Yes, you *could* do it like that.  I've not finished that part (it would be
just a data exchage function).  In researching this issue (like at Code Guru
and Code Project), I came across a program for generating your derived
classes from your database.  I found the non-derived access to be more
convenient - do note that this method is more like VB's method.

> I have a lot of old projects (Dao and ODBC) here waiting for an update and

Yep.

> included a derived recordset which can randomize the data access without
> redundancy.

Whatever that means.

>
>
>
> Baxter <lbax01.spamguard@baxcode.com> wrote in message
> news:102kt0l271ed5b3@corp.supernews.com...
> > I never had much luck with the ClassWizard *changing* a recordset class
> once
> > it was generated.  Any changes had to be hand done, or you had to delete
> and
> > regenerate the entire class.
> >
> > I'm finding that direct field access is more practical - changes have
less
> > impact on your code. Something like:
> >   if (rsTable1.GetIntValue(_T("Field1")) == 1) {
> >     // do something
> >
> > In short, I wrapped the ADO so that I could access the values either
> > individually, or as members of a class.  I'm finding that copying all
the
> > values into current memory as CDaoRecordset and CRecordset do is
> > unnecessary.  If I add a field/column, I don't have to touch existing
code
> > (except for possible init of a new record)
> >



0
Baxter
2/12/2004 5:11:29 PM
When working with MFC CDao classes in seperate worker threads I had a
problem with the COleVariant types which generate an Access Violation
Exception. In my derived classes I have made work-arounds so that the
COleVariant is not used.

Is ADO multi-thread  save, or do I get the same problem?

P.S.: I mean with "randomize the data access without redundancy" that I can
walk through the selected records in a random order while I access each
record ones.

Theo


Baxter <lbax01.spamguard@baxcode.com> wrote in message
news:102ncu3sev8v2c5@corp.supernews.com...
> --
> -------------------------------------------------------------------------
> Free software  - Baxter Codeworks  www.baxcode.com
> -------------------------------------------------------------------------
>
>
> "Theo Buys" <development@noiwal.nl> wrote in message
> news:402b8ed6$0$280$19deed1b@news.inter.NL.net...
> > Can your ADO wrapper classes replace my CDaoRecordset-s without lot of
> > recoding?
>
> Yes, you *could* do it like that.  I've not finished that part (it would
be
> just a data exchage function).  In researching this issue (like at Code
Guru
> and Code Project), I came across a program for generating your derived
> classes from your database.  I found the non-derived access to be more
> convenient - do note that this method is more like VB's method.
>
> > I have a lot of old projects (Dao and ODBC) here waiting for an update
and
>
> Yep.
>
> > included a derived recordset which can randomize the data access without
> > redundancy.
>
> Whatever that means.



0
Theo
2/18/2004 9:15:05 AM
--
-------------------------------------------------------------------------
Free software  - Baxter Codeworks  www.baxcode.com
-------------------------------------------------------------------------


"Theo Buys" <development@noiwal.nl> wrote in message
news:40332e35$0$270$19deed1b@news.inter.NL.net...
> When working with MFC CDao classes in seperate worker threads I had a
> problem with the COleVariant types which generate an Access Violation
> Exception. In my derived classes I have made work-arounds so that the
> COleVariant is not used.

My understanding is that the MFC classes are the problem in multithreading.

>
> Is ADO multi-thread  save, or do I get the same problem?

I've not done enough on ADO to answer your question, but ADO is the
technology MS has selected to replace DAO, and is based on OleDB.  It is
also the technology used by Visual Basic.  I would presume that much would
depend on your Provider.  ADO is set up as an ActiveX object, and for
client-server operation/environment.

>
> P.S.: I mean with "randomize the data access without redundancy" that I
can
> walk through the selected records in a random order while I access each
> record ones.
>
Absolutely. MoveFirst, MoveLast, MoveNext, MovePrevious, and just Move any
number of records from a given position. Find, etc.




0
Baxter
2/18/2004 8:54:50 PM
Reply: