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

书籍源码

开发平台:

Visual C++

  1. // OLEDBMFCBlobSet.h : interface of the COLEDBMFCBlobSet class
  2. //
  3. /////////////////////////////////////////////////////////////////////////////
  4. #if !defined(AFX_OLEDBMFCBLOBSET_H__2126A6EE_B381_11D2_9949_AF1E89DECD4A__INCLUDED_)
  5. #define AFX_OLEDBMFCBLOBSET_H__2126A6EE_B381_11D2_9949_AF1E89DECD4A__INCLUDED_
  6. #if _MSC_VER > 1000
  7. #pragma once
  8. #endif // _MSC_VER > 1000
  9. class CStudent
  10. {
  11. public:
  12. CStudent()
  13. {
  14. memset( (void*)this, 0, sizeof(*this) );
  15. };
  16. char m_FirstName[31];
  17. char m_MidName[31];
  18. char m_LastName[31];
  19. char m_UserID[51];
  20. char m_Password[51];
  21. char m_Address[31];
  22. char m_City[51];
  23. char m_StateOrProvince[21];
  24. char m_PostalCode[21];
  25. char m_PhoneNumber[16];
  26. char m_EMAIL[51];
  27. char m_Major[51];
  28. char m_StudentSSN[31];
  29. ISequentialStream *m_Comments;
  30. BEGIN_COLUMN_MAP(CStudent)
  31. COLUMN_ENTRY_TYPE(1, DBTYPE_STR, m_FirstName)
  32. COLUMN_ENTRY_TYPE(2, DBTYPE_STR, m_MidName)
  33. COLUMN_ENTRY_TYPE(3, DBTYPE_STR, m_LastName)
  34. COLUMN_ENTRY_TYPE(4, DBTYPE_STR, m_UserID)
  35. COLUMN_ENTRY_TYPE(5, DBTYPE_STR, m_Password)
  36. COLUMN_ENTRY_TYPE(6, DBTYPE_STR, m_Address)
  37. COLUMN_ENTRY_TYPE(7, DBTYPE_STR, m_City)
  38. COLUMN_ENTRY_TYPE(8, DBTYPE_STR, m_StateOrProvince)
  39. COLUMN_ENTRY_TYPE(9, DBTYPE_STR, m_PostalCode)
  40. COLUMN_ENTRY_TYPE(10, DBTYPE_STR, m_PhoneNumber)
  41. COLUMN_ENTRY_TYPE(11, DBTYPE_STR, m_EMAIL)
  42. COLUMN_ENTRY_TYPE(12, DBTYPE_STR, m_Major)
  43. COLUMN_ENTRY_TYPE(13, DBTYPE_STR, m_StudentSSN)
  44. BLOB_ENTRY(14, IID_ISequentialStream, 
  45. STGM_READWRITE, 
  46. m_Comments)
  47. END_COLUMN_MAP()
  48. };
  49. class COLEDBMFCBlobSet : public CCommand<CAccessor<CStudent> >
  50. {
  51. public:
  52. HRESULT Open()
  53. {
  54. CDataSource db;
  55. CSession session;
  56. HRESULT hr;
  57. CDBPropSet dbinit(DBPROPSET_DBINIT);
  58. dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
  59. dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "Classes");
  60. dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
  61. dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
  62. hr = db.OpenWithServiceComponents("MSDASQL.1", &dbinit);
  63. if (FAILED(hr))
  64. return hr;
  65. hr = session.Open(db);
  66. if (FAILED(hr))
  67. return hr;
  68. CDBPropSet propset(DBPROPSET_ROWSET);
  69. propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
  70. propset.AddProperty(DBPROP_IRowsetScroll, true);
  71. propset.AddProperty(DBPROP_IRowsetChange, true);
  72. propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE );
  73. hr = CCommand<CAccessor<CStudent> >::Open(session, 
  74. "SELECT FirstName, 
  75. MidName, 
  76. LastName, 
  77. UserID, 
  78. Password, 
  79. Address, 
  80. City, 
  81. StateOrProvince, 
  82. PostalCode, 
  83. PhoneNumber, 
  84. EMAIL, 
  85. Major, 
  86. StudentSSN,
  87. Comments 
  88.    FROM Student",
  89. &propset);
  90. if (FAILED(hr))
  91. return hr;
  92. return MoveNext();
  93. }
  94. };
  95. //{{AFX_INSERT_LOCATION}}
  96. // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
  97. #endif // !defined(AFX_OLEDBMFCBLOBSET_H__2126A6EE_B381_11D2_9949_AF1E89DECD4A__INCLUDED_)