📄 information.h
字号:
// Information.H : Declaration of the CInformation class
#ifndef __INFORMATION_H_
#define __INFORMATION_H_
class CInformationAccessor
{
public:
//"加入自定义代码"
char m_pID[6];
char m_pName[46];
char m_pScore[11];
BEGIN_COLUMN_MAP(CInformationAccessor)
//"加入自定义代码"
COLUMN_ENTRY(1, m_pID) COLUMN_ENTRY(2, m_pName) COLUMN_ENTRY(3, m_pScore)END_COLUMN_MAP()
DEFINE_COMMAND(CInformationAccessor, _T(" \ SELECT \ ID, \ Name, \ Score \ FROM Information"))
// 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 CInformation : public CCommand<CAccessor<CInformationAccessor> >
{
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("..\\ATLOLEDB\\OLE DB.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()
{
//"加入自定义代码" //设置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<CInformationAccessor> >::Open(m_session, NULL, &propset);
// return CCommand<CAccessor<CInformationAccessor> >::Open(m_session);
}
CSession m_session;
};
#endif // __INFORMATION_H_
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -