OLEDBDepartmentMFCSet.h
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:3k
源码类别:

书籍源码

开发平台:

Visual C++

  1. // OLEDBDepartmentMFCSet.h : interface of the COLEDBDepartmentMFCSet class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_OLEDBDEPARTMENTMFCSET_H__3D2A236F_4C1D_11D2_9949_D84454558644__INCLUDED_)
  5. #define AFX_OLEDBDEPARTMENTMFCSET_H__3D2A236F_4C1D_11D2_9949_D84454558644__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. class CDepartment
  10. {
  11. public:
  12. CDepartment()
  13. {
  14. memset( (void*)this, 0, sizeof(*this) );
  15. };
  16. char m_DepartmentCode[5];
  17. char m_DepartmentName[51];
  18. BEGIN_COLUMN_MAP(CDepartment)
  19. COLUMN_ENTRY_TYPE(1, DBTYPE_STR, m_DepartmentCode)
  20. COLUMN_ENTRY_TYPE(2, DBTYPE_STR, m_DepartmentName)
  21. END_COLUMN_MAP()
  22. };
  23. class COLEDBDepartmentMFCSet : public CCommand<CAccessor<CDepartment> >
  24. {
  25. public:
  26. HRESULT Open()
  27. {
  28. CDataSource db;
  29. CSession session;
  30. HRESULT hr;
  31. CDBPropSet dbinit(DBPROPSET_DBINIT);
  32. dbinit.AddProperty(DBPROP_AUTH_CACHE_AUTHINFO, true);
  33. dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);
  34. dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);
  35. dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "");
  36. dbinit.AddProperty(DBPROP_AUTH_PERSIST_ENCRYPTED, false);
  37. dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
  38. dbinit.AddProperty(DBPROP_AUTH_USERID, "Admin");
  39. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "C:\My Documents\Visual C++\Classes.mdb");
  40. dbinit.AddProperty(DBPROP_INIT_MODE, (long)16);
  41. dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
  42. dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, ";COUNTRY=0;CP=1252;LANGID=0x0409");
  43. dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
  44. hr = db.OpenWithServiceComponents("Microsoft.Jet.OLEDB.3.51", &dbinit);
  45. if (FAILED(hr))
  46. return hr;
  47. hr = session.Open(db);
  48. if (FAILED(hr))
  49. return hr;
  50. CDBPropSet propset(DBPROPSET_ROWSET);
  51. propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
  52. propset.AddProperty(DBPROP_IRowsetScroll, true);
  53. propset.AddProperty(DBPROP_IRowsetChange, true);
  54. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE );
  55. hr = CCommand<CAccessor<CDepartment> >::Open(session, "SELECT * FROM Department", &propset);
  56. if (FAILED(hr))
  57. return hr;
  58. return MoveNext();
  59. }
  60. };
  61. //{{AFX_INSERT_LOCATION}}
  62. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  63. #endif // !defined(AFX_OLEDBDEPARTMENTMFCSET_H__3D2A236F_4C1D_11D2_9949_D84454558644__INCLUDED_)