Solved

DAO RecordSet in MFC

Posted on 2002-03-22
6
415 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

In this article, I'll describe -- and show pictures of -- some of the significant additions that have been made available to programmers in the MFC Feature Pack for Visual C++ 2008.  These same feature are in the MFC libraries that come with Visual …
Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
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.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

749 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