?
Solved

DAO RecordSet in MFC

Posted on 2002-03-22
6
Medium Priority
?
427 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 

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 600 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

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

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

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…
In this post we will learn different types of Android Layout and some basics of an Android App.
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.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…
Suggested Courses

777 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