Solved

DAO RecordSet in MFC

Posted on 2002-03-22
6
412 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
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
repeatSeparator  java  challenge 13 58
Perl Awk Need Help 3 128
maven archtype selection in eclipse 1 57
Change to event 1 119
Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
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…
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

829 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