OLEDBDepartmentMFCSet.h
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:3k
源码类别:
书籍源码
开发平台:
Visual C++
- // OLEDBDepartmentMFCSet.h : interface of the COLEDBDepartmentMFCSet class
- //
- /////////////////////////////////////////////////////////////////////////////
- #if !defined(AFX_OLEDBDEPARTMENTMFCSET_H__C270A614_4B8D_11D2_9949_D84454558644__INCLUDED_)
- #define AFX_OLEDBDEPARTMENTMFCSET_H__C270A614_4B8D_11D2_9949_D84454558644__INCLUDED_
- #if _MSC_VER > 1000
- #pragma once
- #endif // _MSC_VER > 1000
- class CDepartment
- {
- public:
- CDepartment()
- {
- ClearFields();
- };
- inline void ClearFields()
- {
- memset( (void*)this, 0, sizeof(*this) );
- };
- char m_DepartmentCode[5];
- char m_DepartmentName[51];
- long m_InstructorID;
- char m_Name[51];
- char m_EMAIL[51];
- char m_Notes[1025];
- BEGIN_COLUMN_MAP(CDepartment)
- COLUMN_ENTRY_TYPE(1, DBTYPE_STR, m_DepartmentCode)
- COLUMN_ENTRY_TYPE(2, DBTYPE_STR, m_DepartmentName)
- COLUMN_ENTRY_TYPE(3, DBTYPE_I4, m_InstructorID)
- COLUMN_ENTRY_TYPE(4, DBTYPE_STR, m_Name)
- COLUMN_ENTRY_TYPE(5, DBTYPE_STR, m_EMAIL)
- COLUMN_ENTRY_TYPE(6, DBTYPE_STR, m_Notes)
- END_COLUMN_MAP()
- };
- class COLEDBDepartmentMFCSet : public CCommand<CAccessor<CDepartment> >
- {
- public:
- CString m_strFilter; //Define a filter
- HRESULT Open()
- {
- CDataSource db;
- CSession session;
- HRESULT hr;
- CDBPropSet dbinit(DBPROPSET_DBINIT);
- //Don't use Access provider since it doesn't support
- //updates very well.
- dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
- dbinit.AddProperty(DBPROP_AUTH_USERID, "sa");
- dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "");
- dbinit.AddProperty(DBPROP_INIT_CATALOG, "Classes");
- dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "(local)");
- dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
- dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
- hr = db.OpenWithServiceComponents("SQLOLEDB.1", &dbinit);
- if (FAILED(hr))
- return hr;
- hr = session.Open(db);
- if (FAILED(hr))
- return hr;
- CDBPropSet propset(DBPROPSET_ROWSET);
- propset.AddProperty(DBPROP_CANFETCHBACKWARDS, true);
- propset.AddProperty(DBPROP_IRowsetScroll, true);
- propset.AddProperty(DBPROP_IRowsetChange, true);
- //2 properties Added by Chuck Wood to allow delayed updates
- propset.AddProperty(DBPROP_CANHOLDROWS, true);
- propset.AddProperty(DBPROP_IRowsetUpdate, true);
- propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE );
- hr = CCommand<CAccessor<CDepartment> >::Open(session,
- "SELECT Department.DepartmentCode,
- Department.DepartmentName,
- Instructor.InstructorID,
- Instructor.Name,
- Instructor.Email,
- Instructor.Notes
- FROM Department INNER JOIN Instructor
- ON Department.DepartmentCode =
- Instructor.DepartmentCode" +
- m_strFilter, &propset);
- if (FAILED(hr))
- return hr;
- return MoveNext();
- }
- };
- //{{AFX_INSERT_LOCATION}}
- // Microsoft Visual C++ will insert additional declarations immediately before the previous line.
- #endif // !defined(AFX_OLEDBDEPARTMENTMFCSET_H__C270A614_4B8D_11D2_9949_D84454558644__INCLUDED_)