Solved

DAO RecordSet in MFC

Posted on 2002-03-22
6
407 Views
Last Modified: 2013-11-20
This project is to help learn how to use DAO objects in MFC.

I created a new Console appliction with MFC support.

I added a new class to it called BTable.  It is derived from CDAORecordSet.  I am using a .MDB for my table.

In the _tmain function of theApp I want to output the contents of the fields in the records of the DAO RecordSet object.

EX:
    cout << m_pSet->m_Chapter << endl;

Where m_pSet is the pointer to the RecordSet in the BTable class and m_Chapter is a member variable that is attached to a field.

I'm giving this question 200 points because either I'm missing something real obvious or the "cost of admission" to access the DAORecordSet is high.

Thanx
Dave
0
Comment
Question by:Smave
6 Comments
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 6890390
Try this

CDaoDatabase db;
   db.Open(_T("yourMDBPath\FileName.mdb"));

   BTable rs(&db);
   rs.Open();

   while (!rs.IsEOF())
   {
      cout << m_pSet->m_Chapter << endl;

      rs.MoveNext();
   }
   rs.Close();
   db.Close();


GOOD LUCK
0
 
LVL 23

Expert Comment

by:Roshan Davis
ID: 6890401
Try this

  CDaoDatabase db;
  db.Open(_T("yourMDBPath\FileName.mdb"));

  BTable *m_pSet = new BTable(&db);
  rs.Open();

  while (!m_pSet->IsEOF())
  {
     cout << m_pSet->m_Chapter << endl;

     m_pSet->MoveNext();
  }
  m_pSet->Close();
  db.Close();
 
  delete m_pSet;


GOOD LUCK
0
 
LVL 2

Expert Comment

by:gandalf79
ID: 6890454
smave

if i understand your explaination your program should look something like this.

class BTable : public CDAORecordSet {
//...
pubic:
   short m_Chapter;
//...
};

//...

void _tmain() {
   //...
   BTable* pSet = new BTable;
   //...
   cout << pSet->m_Chapter << endl;
   //...
}

if this is not the case then try to modify your code to look more like this. if not please post a little more code so we can better help you.

justus
0
Is Your AD Toolbox Looking More Like a Toybox?

Managing Active Directory can get complicated.  Often, the native tools for managing AD are just not up to the task.  The largest Active Directory installations in the world have relied on one tool to manage their day-to-day administration tasks: Hyena. Start your trial today.

 

Author Comment

by:Smave
ID: 6890810
Instead of posting a lot of code I ziiped up the whole project and posted it at:
http://webpages.charter.net/avionicace/hold/

roshmon, I used the MFC ClassWizard to add the BTable class (derived from CDAORecordSet) so the code you posted is somewhat redundant to what's allready in that class.  I'm pretty sure what you wrote would work, but like I said I'm useing this project as a learning tool.  I'm trying to get the jist of calling functions from another class.

thanx
Dave
0
 
LVL 4

Expert Comment

by:inpras
ID: 6891246
         BTable bt(NULL);
          bt.Open();
          bt.MoveFirst();
          while (!bt.IsEOF())
          {
               cout << (LPCSTR)bt.m_1769_Authorized << endl;
               bt.MoveNext();
     
          }
          bt.Close();
remember Cout does not take CString value
0
 
LVL 2

Accepted Solution

by:
gandalf79 earned 200 total points
ID: 6892358
int _tmain(int argc, TCHAR* argv[], TCHAR* envp[])
{
int nRetCode = 0;

// initialize MFC and print and error on failure
if (!AfxWinInit(::GetModuleHandle(NULL), NULL, ::GetCommandLine(), 0))
{
 // TODO: change error code to suit your needs
 cerr << _T("Fatal Error: MFC initialization failed") << endl;
 nRetCode = 1;
}
else
{
 // TODO: code your application's behavior here.
 CString strHello;
 strHello.LoadString(IDS_HELLO);
 cout << (LPCTSTR)strHello << endl;

 //here is where I want to 'cout' the contents of the fields in
 //the table
 BTable* pBTbl1 = new BTable(NULL);
 if(!pBTbl1->IsOpen())
  pBTbl1->Open();

 cout << "PrimeKey: " << pBTbl1->m_PrimeKey << endl;
 cout << "Book Title: " << (LPCTSTR)pBTbl1->m_BookTitle << endl;
 cout << "Book Number: " << pBTbl1->m_BookNumber << endl;
 cout << "Chapter: " << pBTbl1->m_Chapter << endl;
 cout << "Verse: " << pBTbl1->m_Verse << endl;
 cout << "English: " << (LPCTSTR)pBTbl1->m_1769_Authorized << endl;
 cout << "Non-English: " << (LPCTSTR)pBTbl1->m_NotEnglish << endl;

 pBTbl1->Close();
 delete pBTbl1;
}

return nRetCode;
}
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
cat dog challenge 18 124
Define unique primary key 9 92
twoTwo  challenge 35 103
Problem to event 3 97
Introduction: Finishing the grid – keyboard support for arrow keys to manoeuvre, entering the numbers.  The PreTranslateMessage function is to be used to intercept and respond to keyboard events. Continuing from the fourth article about sudoku. …
Introduction: Dialogs (1) modal - maintaining the database. Continuing from the ninth article about sudoku.   You might have heard of modal and modeless dialogs.  Here with this Sudoku application will we use one of each type: a modal dialog …
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question