基于MFC和ACCESS的学生综合素质能力评价系统软件开发(4-项目录入)

注:本文所涉及软件已申请软件著作权,请勿盗版,侵权必究。

文章目录


四、项目录入

项目录入与登录框类似:
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-主界面)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值