home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Windows Gam…ming Gurus (2nd Edition) / Disc2.iso / msdn_vcb / samples / vc98 / mfc / database / mfcrows / mfcrowset.h < prev    next >
C/C++ Source or Header  |  1998-03-26  |  2KB  |  77 lines

  1. // MFCRowSet.h : interface of the CMFCRowSet class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1998 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #if !defined(AFX_MFCROWSET_H__2B60A706_22FC_11D1_8FD3_000000000000__INCLUDED_)
  14. #define AFX_MFCROWSET_H__2B60A706_22FC_11D1_8FD3_000000000000__INCLUDED_
  15.  
  16. #if _MSC_VER >= 1000
  17. #pragma once
  18. #endif // _MSC_VER >= 1000
  19.  
  20. class CProduct
  21. {
  22. public:
  23.     long    m_nProductID;
  24.     TCHAR   m_szName[41];
  25.  
  26. DEFINE_COMMAND(CProduct, _T("SELECT ProductID, ProductName FROM Products"))
  27.  
  28. BEGIN_ACCESSOR_MAP(CProduct, 2)
  29.     BEGIN_ACCESSOR(0, true)
  30.         COLUMN_ENTRY(1, m_nProductID)
  31.     END_ACCESSOR()
  32.     BEGIN_ACCESSOR(1, true)
  33.         COLUMN_ENTRY(2, m_szName)
  34.     END_ACCESSOR()
  35. END_ACCESSOR_MAP()
  36. };
  37.  
  38. class CMFCRowSet : public CCommand<CAccessor<CProduct> >
  39. {
  40. public:
  41.     //CMFCRowSet();
  42.     DECLARE_DYNAMIC(CMFCRowSet)
  43.  
  44.     HRESULT Open()
  45.     {
  46.         CDataSource db;
  47.         CSession    session;
  48.         HRESULT     hr;
  49.  
  50.         hr = db.Open(_T("MSDASQL"), _T("OLE_DB_NWind_Jet"), _T("Admin"), _T(""));
  51.         if (FAILED(hr))
  52.             return hr;
  53.  
  54.         hr = session.Open(db);
  55.         if (FAILED(hr))
  56.             return hr;
  57.  
  58.         CDBPropSet  propset(DBPROPSET_ROWSET);
  59.         propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
  60.         propset.AddProperty(DBPROP_IRowsetScroll, true);
  61.         propset.AddProperty(DBPROP_IRowsetChange, true);
  62.         propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE);
  63.  
  64.         hr = CCommand<CAccessor<CProduct> >::Open(session, NULL, &propset);
  65.         if (FAILED(hr))
  66.             return hr;
  67.  
  68.         return MoveNext();
  69.     }
  70.  
  71. };
  72.  
  73. //{{AFX_INSERT_LOCATION}}
  74. // Microsoft Developer Studio will insert additional declarations immediately before the previous line.
  75.  
  76. #endif // !defined(AFX_MFCROWSET_H__2B60A706_22FC_11D1_8FD3_000000000000__INCLUDED_)
  77.