Solved

DAO RecordSet in MFC

Posted on 2002-03-22
6
397 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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
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.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

758 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

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now