Database CDaoDatabase 
Author Message
 Database CDaoDatabase

All,
I am working on a DialogBox app that get the information from a .mdb file
and put the info in a list view.  All I want to do is Open the file, get the
info and and put it in a list control then close the file.  I can open and
close the file(thats easy) but I cannot get any info out of it.  It might
be easier with VB, but I am not that good with it and I would rather do it
with VC++ 5.0.  If any one has a sample that does something like that I
would love to see the code.  Thanks in advance...



Fri, 08 Dec 2000 03:00:00 GMT  
 Database CDaoDatabase

What you need to do is either use DAO or ODBC to access an mdb file
DAO in this case would be better for an Access file.

To add database support do the following:
1. In the Stdafx.h file add #include <afxdao.h>
2. Call the class wizard (Ctrl + W) and create a new class with "Add Class";
"New"
3. Give the class a name and select as "Base class" CDaoRecordset.
4. Select the mdb file and the table you want to use.
5. In the file you want to use the database, include the header file of the
recordset (eg #include "Myrecodset")
6. Define a variable of your recordset (eg. CMyRecordset Myset;)
7. Open the database where you need it (MySet.Open();)
8. Now you can access the database as needed. (check the member variables of the
recorset in the class wizard)
9 Use the following functions: MoveNext, Move, Edit, New Update... to navigate
and change data in the database

Hope this helps
Guido

The Brain schrieb:

Quote:
> All,
> I am working on a DialogBox app that get the information from a .mdb file
> and put the info in a list view.  All I want to do is Open the file, get the
> info and and put it in a list control then close the file.  I can open and
> close the file(that's easy) but I cannot get any info out of it.  It might
> be easier with VB, but I am not that good with it and I would rather do it
> with VC++ 5.0.  If any one has a sample that does something like that I
> would love to see the code.  Thanks in advance...



Sat, 09 Dec 2000 03:00:00 GMT  
 Database CDaoDatabase

ChechOut DAOVIEW sample which comes with VC5.0,which exactly suites your
requirement



Sat, 09 Dec 2000 03:00:00 GMT  
 Database CDaoDatabase

The following snippet reads the fields "SomeText" and "SomeNumber" from the
query "SomeQuery" in a file db4.mdb.  You can use the other functions of
CDaoRecordset (MoveNext() and IsEOF()) to iterate through all of the rows.
You'll have to pull apart the COleVariant structures to get the useful data
out of them.  You can use a CDaoTableDef it is just a plain table and not a
query.

#include <afxdao.h>

void foo() {
 CDaoDatabase DB;
 DB.Open("db4.mdb");

 CDaoQueryDef TD(&DB);
 TD.Open("SomeQuery");

 CDaoRecordset RS(&DB);
 RS.Open(&TD);

 RS.MoveFirst();

 COleVariant U, V;
 U= RS.GetFieldValue("SomeText");
 V= RS.GetFieldValue("SomeNumber");

Quote:
}

The following snippet stuffs values into a list box.  The variable m_List1
is of type CListBox and was creating using the Class Wizard in my example.

void bar() {
 m_List1.AddString("Foo");
 m_List1.AddString("Bar");
 m_List1.AddString("Hag");

Quote:
}

>All,
>I am working on a DialogBox app that get the information from a .mdb file
>and put the info in a list view.  All I want to do is Open the file, get
the
>info and and put it in a list control then close the file.  I can open and
>close the file(thats easy) but I cannot get any info out of it.  It might
>be easier with VB, but I am not that good with it and I would rather do it
>with VC++ 5.0.  If any one has a sample that does something like that I
>would love to see the code.  Thanks in advance...



Sat, 09 Dec 2000 03:00:00 GMT  
 Database CDaoDatabase

Don't do what I did one time.  I just assumed my database had data in it.
I tried to get my code to work for days until I realized my mdb tables had
no data in them.

There's a perfect example in the Tutorial section of your Visual C++ CDROM
for what you want to do.

Search for "Tutorial Example: Enroll"

Doug Pan...

Quote:

>All,
>I am working on a DialogBox app that get the information from a .mdb file
>and put the info in a list view.  All I want to do is Open the file, get
the
>info and and put it in a list control then close the file.  I can open and
>close the file(that's easy) but I cannot get any info out of it.  It might
>be easier with VB, but I am not that good with it and I would rather do it
>with VC++ 5.0.  If any one has a sample that does something like that I
>would love to see the code.  Thanks in advance...



Sat, 09 Dec 2000 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Database CDaoDatabase

2. Enter data to a database using CDaoDatabase

3. Using multiple databases in CDaoDatabase?

4. How to create a new Access database, table, and field using CDaoDatabase, CDasoTableDef

5. Creating Access 2000 Database with CDaoDatabase

6. How to Backup the Contacts Database&#12289;Tasks Database&#12289;Appointment Database

7. Set "CDaoDatabase" variable to "LPDISPATCH" Database variable

8. Using CDaoDatabase/CDaoRecordset from inside an ATL/MFC COM Component

9. Closing CDaoDatabase gives Assertion error

10. Help: CDaoDatabase from multiple threads

11. CDAODatabase::ExecuteSQL

12. (Q) URGENT - CDaoDatabase doesn't succeed, fail or except in Release mode

 

 
Powered by phpBB® Forum Software