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

📄 department.h

📁 vc++6.0数据库编程大全一书得各个章节得源码,比较详细.可以仔细参照学习!
💻 H
字号:
// Department.H : Declaration of the CDepartment class

#ifndef __DEPARTMENT_H_
#define __DEPARTMENT_H_

class CDepartmentAccessor
{
public:
	TCHAR m_DepartmentCode[5];	TCHAR m_DepartmentName[51];
BEGIN_COLUMN_MAP(CDepartmentAccessor)
	COLUMN_ENTRY(1, m_DepartmentCode)	COLUMN_ENTRY(2, m_DepartmentName)END_COLUMN_MAP()

DEFINE_COMMAND(CDepartmentAccessor, _T(" \	SELECT \		DepartmentCode, \		DepartmentName  \		FROM Department"))

	// 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 CDepartment : public CCommand<CAccessor<CDepartmentAccessor> >
{
public:
	//Constructor added by Chuck Wood
	CDepartment () {
		//Allow 1 k for SQL WHERE clause
		m_strFilter = new char[1];
		strcpy (m_strFilter, "");
	}
	//Destructor added by Chuck Wood
	~CDepartment () {
		//Release resources
		delete m_strFilter;
	}
	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_CACHE_AUTHINFO, true);		dbinit.AddProperty(DBPROP_AUTH_ENCRYPT_PASSWORD, false);		dbinit.AddProperty(DBPROP_AUTH_MASK_PASSWORD, false);		dbinit.AddProperty(DBPROP_AUTH_PASSWORD, OLESTR(""));		dbinit.AddProperty(DBPROP_AUTH_PERSIST_ENCRYPTED, false);		dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false);		dbinit.AddProperty(DBPROP_AUTH_USERID, OLESTR("Admin"));		dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("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, OLESTR(";COUNTRY=0;CP=1252;LANGID=0x0409"));		dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);		hr = db.Open(_T("Microsoft.Jet.OLEDB.3.51"), &dbinit);
		if (FAILED(hr))
			return hr;

		return m_session.Open(db);
	}
	HRESULT OpenRowset()
	{
		// Set properties for open
		CDBPropSet	propset(DBPROPSET_ROWSET);
		propset.AddProperty(DBPROP_IRowsetChange, true);
		propset.AddProperty(DBPROP_UPDATABILITY, DBPROPVAL_UP_CHANGE | DBPROPVAL_UP_INSERT | DBPROPVAL_UP_DELETE);

		//The rest of this function was added by Chuck Wood
		//Allow 512 bytes for the new SQL Command
		char newSQL[512];
		char *SQLCommand;
		GetDefaultCommand((const char **) &SQLCommand);
		strcpy(newSQL, SQLCommand);
		if (strlen(m_strFilter)) {
			strcat(newSQL, " WHERE ");
			strcat(newSQL, m_strFilter);
		}
		return CCommand<CAccessor<CDepartmentAccessor> >
				::Open(m_session, newSQL, &propset);
	}
	char	 	*m_strFilter;
	CSession	m_session;
};
#endif // __DEPARTMENT_H_

⌨️ 快捷键说明

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