Using the OLE DB Consumer Code

Using the database consumer class is just about as easy as creating it. Here's how to take advantage of the database consumer class:

  1. Declare an instance of CAuthors wherever you need to use it:

    class CUseAuthors : public CDialog {     CAuthors m_authors;     .     .     . };

  2. Open the Authors database by calling Open on the database consumer object:

    CUseAuthors::OnInitDialog() {     m_authors.Open(); }

  3. Use member functions to navigate through and manipulate the database. Here's a short sampling of some of the things you can do:

    CUseAuthors::OnNext() {     m_authors.MoveNext(); } CUseAuthors::OnFirst() {     m_authors.MoveFirst(); } CUseAuthors::OnLast() {     m_authors.MoveLast(); } CUseAuthors::OnInsert() {     m_authors.Insert(); }

  4. As you navigate through the database, the data ends up in the member variables. For example, if you want to find out the name of the next author in the database, the code would look like this:

    m_authors.MoveNext(); m_strAuthorName = m_authors.m_Author;

As you can see, using the templates greatly simplifies getting the data out of the database. All you need to do is find the database, point the ATL Object Wizard there, and get the Wizard to generate your code. Then the accessor class has functions useful for moving around the database and fetching the data. The other half of the OLE DB Template equation is the data provider. Here's a rundown of how to work with providers.



Programming Microsoft Visual C++
Programming Microsoft Visual C++
ISBN: 1572318570
EAN: 2147483647
Year: 1997
Pages: 332

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net