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

书籍源码

开发平台:

Visual C++

  1. // OLEDBDepartmentMFCSet.h : interface of the COLEDBDepartmentMFCSet class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_OLEDBDEPARTMENTMFCSET_H__246081F1_D830_11D2_9949_D89162B4264B__INCLUDED_)
  5. #define AFX_OLEDBDEPARTMENTMFCSET_H__246081F1_D830_11D2_9949_D89162B4264B__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_PERSIST_SENSITIVE_AUTHINFO, false);
  33. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "Classes");
  34. dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
  35. dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
  36. hr = db.OpenWithServiceComponents("MSDASQL.1", &dbinit);
  37. if (FAILED(hr))
  38. return hr;
  39. hr = session.Open(db);
  40. if (FAILED(hr))
  41. return hr;
  42. CDBPropSet propset(DBPROPSET_ROWSET);
  43. propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
  44. propset.AddProperty(DBPROP_IRowsetScroll, true);
  45. propset.AddProperty(DBPROP_IRowsetChange, true);
  46. //2 properties Added by Chuck Wood to allow delayed updates
  47. propset.AddProperty(DBPROP_CANHOLDROWS, true);
  48. propset.AddProperty(DBPROP_IRowsetUpdate, true);
  49. //*************************
  50. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE );
  51. hr = CCommand<CAccessor<CDepartment> >::Open(session, "SELECT * FROM Department", &propset);
  52. if (FAILED(hr))
  53. return hr;
  54. return MoveNext();
  55. }
  56. };
  57. //{{AFX_INSERT_LOCATION}}
  58. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  59. #endif // !defined(AFX_OLEDBDEPARTMENTMFCSET_H__246081F1_D830_11D2_9949_D89162B4264B__INCLUDED_)