?? students.h
字號:
// Students.H : Declaration of the CStudents class
#ifndef __STUDENTS_H_
#define __STUDENTS_H_
class CStudentsAccessor
{
public:
LONG m_age; //年齡下 TCHAR m_department[51]; //系別 LONG m_id; //學號 TCHAR m_name[51]; //姓名
BEGIN_COLUMN_MAP(CStudentsAccessor)
COLUMN_ENTRY(1, m_id) COLUMN_ENTRY(2, m_name) COLUMN_ENTRY(3, m_age) COLUMN_ENTRY(4, m_department)END_COLUMN_MAP()
DEFINE_COMMAND(CStudentsAccessor, _T(" \ SELECT \ id, \ name, \ age, \ department \ FROM students"))
// 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 CStudents : public CCommand<CAccessor<CStudentsAccessor> >
{
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_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_USERID, OLESTR("Admin")); dbinit.AddProperty(DBPROP_INIT_DATASOURCE, OLESTR("students.mdb")); dbinit.AddProperty(DBPROP_INIT_MODE, (long)16); dbinit.AddProperty(DBPROP_INIT_PROMPT, (short)4); dbinit.AddProperty(DBPROP_INIT_PROVIDERSTRING, OLESTR("")); dbinit.AddProperty(DBPROP_INIT_LCID, (long)1033);// dbinit.AddProperty(DBPROP_AUTH_PERSIST_SENSITIVE_AUTHINFO, false); hr = db.Open(_T("Microsoft.Jet.OLEDB.4.0"), &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);
return CCommand<CAccessor<CStudentsAccessor> >::Open(m_session, NULL, &propset);
}
CSession m_session;
};
#endif // __STUDENTS_H_
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -