注:本文所涉及软件已申请软件著作权,请勿盗版,侵权必究。
文章目录
四、项目录入
项目录入与登录框类似:
1、新建一个Dialog,为它新建一个类,命名为CDlg_ProjectReg
2、所有的EditBox和ComboBox定义好相应的成员变量
3、为ComboBox添加消息响应函数(以ProjType为例):
void CDlg_ProjectReg::OnSelchangeComboProjectType()
{
// TODO: Add your control notification handler code here
int nIndex = m_cbProjType.GetCurSel();
m_cbProjType.GetLBText( nIndex, m_strProjType);
}
4、在OnOK响应函数中添加:
this->UpdateData(true);
try
{
::CoInitialize(NULL);
this->m_pConnection.CreateInstance(__uuidof(Connection));
this->m_pRecordset.CreateInstance(__uuidof(Recordset));
this->m_pConnection->Open("DSN=TQES_DATABASE","","",0);//上面四行为打开数据源连接
}
catch(_com_error e)
{
AfxMessageBox("数据库连接失败!");
CDlg_ProjectReg::OnCancel();
}
try
{
this->m_pRecordset->Open("select * from PROJECT",(IDispatch*)this->m_pConnection,adOpenDynamic,adLockOptimistic,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("打开表PROJECT失败!");
CDlg_ProjectReg::OnCancel();
}
try
{
this->m_pRecordset->MoveNext();
this->m_pRecordset->AddNew();
this->m_pRecordset->PutCollect("USER_ID",_variant_t(m_Student_ID));
this->m_pRecordset->PutCollect("PROJ_NO",_variant_t(m_Project_ID));
this->m_pRecordset->PutCollect("PROJ_TYPE",_variant_t(m_strProjectType));
this->m_pRecordset->PutCollect("PROJ_NAME",_variant_t(m_ProjectName));
this->m_pRecordset->PutCollect("PROJ_LEVEL",_variant_t(m_strProjectLevel));
this->m_pRecordset->PutCollect("PROJ_RANK",_variant_t(m_strProjectRank));
this->m_pRecordset->PutCollect("PROJ_ABSTRACT",_variant_t(m_strProjectAbstract));
this->m_pRecordset->Update();
}
catch(_com_error e)
{
AfxMessageBox("新增数据失败!");
CDlg_ProjectReg::OnCancel();
}
AfxMessageBox("保存数据成功!");
//关闭连接
CoUninitialize();
this->m_pRecordset->Close();
this->m_pConnection->Close();
CDialog::OnOK();
当然不要忘了为该类添加成员变量:
_ConnectionPtr m_pConnection;
_RecordsetPtr m_pRecordset;
最后运行效果:
在数据库里可以查看已添加的数据。
其他内容(竞赛、成绩等)的录入与此类似,不再赘述。
下一篇:基于MFC和ACCESS的学生综合素质能力评价系统软件开发(5-主界面目录)
上一篇:基于MFC和ACCESS的学生综合素质能力评价系统软件开发(3-主界面)