OldStudent.H
上传用户:benben_wyd
上传日期:2010-02-26
资源大小:1229k
文件大小:3k
- // StudentsPerClass.H : Declaration of the CStudentsPerClass class
- #ifndef __STUDENTSPERCLASS_H_
- #define __STUDENTSPERCLASS_H_
- class CStudentsPerClassAccessor
- {
- public:
- TCHAR m_DepartmentName[51];
- TCHAR m_Description[51];
- LONG m_NumberOfStudents;
- BEGIN_COLUMN_MAP(CStudentsPerClassAccessor)
- COLUMN_ENTRY(1, m_DepartmentName)
- COLUMN_ENTRY(2, m_Description)
- COLUMN_ENTRY(3, m_NumberOfStudents)
- END_COLUMN_MAP()
- DEFINE_COMMAND(CStudentsPerClassAccessor, _T("
- SELECT
- DepartmentName,
- Description,
- Count(StudentID) AS NumberOfStudents
- FROM (Department
- INNER JOIN (Class
- INNER JOIN Section
- ON Class.ClassID = Section.ClassID)
- ON Department.DepartmentCode
- = Class.DepartmentCode)
- LEFT JOIN StudentClass
- ON Section.SectionID
- = StudentClass.SectionID
- GROUP BY DepartmentName,
- Description
- "))
- /*
- DEFINE_COMMAND(CStudentsPerClassAccessor, _T("
SELECT
- DepartmentName,
- Description,
- Count(StudentID) AS NumberOfStudents
- FROM ((Department
- INNER JOIN (Class
- INNER JOIN Section
- ON Class.ClassID = Section.ClassID)
- ON Department.DepartmentCode
- = Class.DepartmentCode)
- LEFT JOIN StudentClass
- ON Section.SectionID
- = StudentClass.SectionID
- GROUP BY DepartmentName,
- Description
- "))
- */
- CStudentsPerClassAccessor () //Constructor added by cw
- {
- ClearRecord();
- }
- // You may wish to call this function if you are inserting a record and wish to
- // initialize all the fields, if you are not going to explicitly set all of them.
- void ClearRecord()
- {
- memset(this, 0, sizeof(*this));
- }
- };
- class CStudentsPerClass : public CCommand<CAccessor<CStudentsPerClassAccessor> >
- {
- public:
- HRESULT Open()
- {
- CDataSource db;
- CSession session;
- HRESULT hr;
- CDBPropSet dbinit(DBPROPSET_DBINIT);
- dbinit.AddProperty(DBPROP_AUTH_CACHE_AUTHINFO, true);
- dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);
- dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);
- dbinit.AddProperty(DBPROP_AUTH_PASSWORD, "");
- dbinit.AddProperty(DBPROP_AUTH_PERSIST_ENCRYPTED, false);
- dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);
- dbinit.AddProperty(DBPROP_AUTH_USERID, "Admin");
- dbinit.AddProperty(DBPROP_INIT_DATASOURCE, "C:\My Documents\Visual C++\Classes.mdb");
- dbinit.AddProperty(DBPROP_INIT_MODE, (long)16);
- dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);
- dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, ";COUNTRY=0;CP=1252;LANGID=0x0409");
- dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);
- hr = db.OpenWithServiceComponents("Microsoft.Jet.OLEDB.3.51", &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);
- propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE );
- hr = CCommand<CAccessor<CStudentsPerClassAccessor> >::Open(session, NULL, &propset);
- if (FAILED(hr))
- return hr;
- return MoveFirst();
- }
- };
- #endif // __STUDENTSPERCLASS_H_