Using the database consumer class is just about as easy as creating it. Here's how to take advantage of the database consumer class:
class CUseAuthors : public CDialog { CAuthors m_authors; . . . };
CUseAuthors::OnInitDialog() { m_authors.Open(); }
CUseAuthors::OnNext() { m_authors.MoveNext(); } CUseAuthors::OnFirst() { m_authors.MoveFirst(); } CUseAuthors::OnLast() { m_authors.MoveLast(); } CUseAuthors::OnInsert() { m_authors.Insert(); }
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.