Click here to Skip to main content
15,885,200 members
Articles / Desktop Programming / MFC
Article

DAO library extension

Rate me:
Please Sign up or sign in to vote.
3.80/5 (7 votes)
4 Mar 20022 min read 88.4K   1.6K   24   6
My added DAO functionality makes database reading and writing easier

Introduction

DAO database library DLL

I have noticed that working with DAO databases and recordsets can often be tedious and time consuming, which is why I created this DAO database library. My goal was to create a library to speed up coding time when working with DAO. My classes inherit from the base DAO classes so no functionality is lost.

My library allows you to 

  1. quickly open database and recordset objects,
  2. close them quickly without worrying about memory leaks, 
  3. easily read and write from the database for specific data types.

These functions are not intended to replace CDaoDatabase/CDaoRecordset functionality, but rather extend them for reduced coding.

I. DLL Setup

1. Open the project and compile the DLL using "rebuild all", it will create a .dll and .lib file for you in your release folder.

II. Client EXE Setup

  1. In project -> settings -> link -> object libraries include daolibrary.lib 
  2. In Release folder add daolibrary.dll 
  3. In project workspace add daolibrary.lib 
  4. Add dllHeader.h to project and following lines in client .cpp file.
#include "dllHeader.h" 
CDaoDB db; // database 
CDaoRS rs; // recordset

Functions available:

CDaoDB Documentation Class CDaoDB extends the CDaoDatabase class

bool CDaoDB::dbOpen(CString strFilePathName);

Opens connection to CDaoDatabase given a database filename with path.

bool CDaoDB::dbClose();

Closes the CDaoDatabase, deletes variables to prevent memory leaking.

CString CDaoDB::GetTableName(int tableNum);

Returns the name of a table based on the table number.

CDaoRS Documentation Class CDaoRS extends the CDaoRecordset class bool CDaoRS::rsOpen(CString sql,CDaoDatabase* db);

Opens connection to CDaoRecordset given sql and database. i.e. 

rs.rsOpen("SELECT * FROM TABLE",database.db);

*note that this opens the recordset as dbOpenDynaset

bool CDaoRS::rsClose();

Closes the CDaoRecordset, deletes variables to prevent memory leaking.

double CDaoRS::GetAsDouble(int col);

Returns a double value from the specified column in the recordset.

int CDaoRS::GetAsInt(int col);

Returns an int value from the specified column in the recordset.

long CDaoRS::GetAsLong(int col);

Returns a long value from the specified column in the recordset.

CString CDaoRS::GetAsString(int col);

Returns a long value from the specified column in the recordset.

CString CDaoRS::GetDateAsString(int col);

Returns a date value in CString format from the specified column in the recordset. The

CString
will be returned with mm/dd/yyy format.

CString CDaoRS::GetTimeAsString(int col);

Returns a date value in CString format from the specified column in the recordset. The

CString
will be returned with hh:mm:ss format.

void CDaoRS::SetAsString(CString field,CString string);

Set specified fieldname field in recordset to the CString value string.

void CDaoRS::SetAsInt(CString field,int integer);

Set specified fieldname field in recordset to the integer value int.

void CDaoRS::SetAsLong(CString field,long lngValue);

Set specified fieldname field in recordset to the long value lngValue.

void CDaoRS::SetAsDouble(CString field,double dblValue);

Set specified fieldname field in recordset to the double value dblValue.

CString CDaoRS::GetFieldName(int col);

Returns the field name of the specified column number in the recordset.

int CDaoRS::GetRecordCount();

Returns the number of records in the recordset.

Please give suggestions for other functions you would like to see in here. Sample client app will be available soon...

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
Software developer, for Interactive Metronome (http://www.interactivemetronome.com).

BA Computer Science, Calvin College

Comments and Discussions

 
Generalreport error Pin
ewighell29-Oct-05 3:32
ewighell29-Oct-05 3:32 
Generaldatabase.Create() generates 97 db format Pin
general.failure14-Jul-03 2:13
general.failure14-Jul-03 2:13 
GeneralRe: database.Create() generates 97 db format Pin
Anonymous14-Jul-03 5:09
Anonymous14-Jul-03 5:09 
GeneralRe: database.Create() generates 97 db format Pin
Anonymous20-Jul-03 2:33
Anonymous20-Jul-03 2:33 
GeneralDAO Crash Pin
RLupan25-Feb-03 3:28
RLupan25-Feb-03 3:28 
GeneralSample client app 's needed. Pin
6-May-02 21:31
suss6-May-02 21:31 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.