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. long m_InstructorID;
  23. char m_Name[51];
  24. char m_EMAIL[51];
  25. char m_Notes[1025];
  26. BEGIN_COLUMN_MAP(CDepartment)
  27. COLUMN_ENTRY_TYPE(1, DBTYPE_STR, m_DepartmentCode)
  28. COLUMN_ENTRY_TYPE(2, DBTYPE_STR, m_DepartmentName)
  29. COLUMN_ENTRY_TYPE(3, DBTYPE_I4, m_InstructorID)
  30. COLUMN_ENTRY_TYPE(4, DBTYPE_STR, m_Name)
  31. COLUMN_ENTRY_TYPE(5, DBTYPE_STR, m_EMAIL)
  32. COLUMN_ENTRY_TYPE(6, DBTYPE_STR, m_Notes)
  33. END_COLUMN_MAP()
  34. };
  35. class COLEDBDepartmentMFCSet : public CCommand<CAccessor<CDepartment> >
  36. {
  37. public:
  38. CString m_strFilter; //Define a filter
  39. HRESULT Open()
  40. {
  41. CDataSource db;
  42. CSession session;
  43. HRESULT hr;
  44. CDBPropSet dbinit(DBPROPSET_DBINIT);
  45. //Don't use Access provider since it doesn't support
  46. //updates very well.
  47. dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
  48. dbinit.AddProperty(DBPROP_AUTH_USERID, "sa");
  49. dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "");
  50. dbinit.AddProperty(DBPROP_INIT_CATALOG,  "Classes");
  51. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "(local)");
  52. dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
  53. dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
  54. hr = db.OpenWithServiceComponents("SQLOLEDB.1", &dbinit);
  55. if (FAILED(hr))
  56. return hr;
  57. hr = session.Open(db);
  58. if (FAILED(hr))
  59. return hr;
  60. CDBPropSet propset(DBPROPSET_ROWSET);
  61. propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
  62. propset.AddProperty(DBPROP_IRowsetScroll, true);
  63. propset.AddProperty(DBPROP_IRowsetChange, true);
  64. //2 properties Added by Chuck Wood to allow delayed updates
  65. propset.AddProperty(DBPROP_CANHOLDROWS, true);
  66. propset.AddProperty(DBPROP_IRowsetUpdate, true);
  67. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE );
  68. hr = CCommand<CAccessor<CDepartment> >::Open(session, 
  69. "SELECT Department.DepartmentCode,
  70. Department.DepartmentName,
  71. Instructor.InstructorID,
  72. Instructor.Name,
  73. Instructor.Email,
  74. Instructor.Notes
  75. FROM    Department INNER JOIN Instructor
  76. ON Department.DepartmentCode =
  77. Instructor.DepartmentCode" + 
  78. m_strFilter, &propset);
  79. if (FAILED(hr))
  80. return hr;
  81. return MoveNext();
  82. }
  83. };
  84. //{{AFX_INSERT_LOCATION}}
  85. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  86. #endif // !defined(AFX_OLEDBDEPARTMENTMFCSET_H__C270A614_4B8D_11D2_9949_D84454558644__INCLUDED_)