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