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

📄 oldstudent.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 \
"))
/*
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_

⌨️ 快捷键说明

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