⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 studentsperclass.h

📁 vc++6.0数据库编程大全一书得各个章节得源码,比较详细.可以仔细参照学习!
💻 H
字号:
// 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 \
"))

	// 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()
	{
		HRESULT		hr;

		hr = OpenDataSource();
		if (FAILED(hr))
			return hr;

		return OpenRowset();
	}
	HRESULT OpenDataSource()
	{
		HRESULT		hr;
		CDataSource db;
		CDBPropSet	dbinit(DBPROPSET_DBINIT);

		dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);		dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("Classes"));		dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4);		dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);		hr = db.Open(_T("MSDASQL"), &dbinit);
		if (FAILED(hr))
			return hr;

		return m_session.Open(db);
	}
	HRESULT OpenRowset()
	{
		return CCommand<CAccessor<CStudentsPerClassAccessor> >::Open(m_session);
	}
	CSession	m_session;
};

#endif // __STUDENTSPERCLASS_H_

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -