MFC和ado数据库使用时遇到的问题

=================================================================== 

第一个
===================================================================
try{
		CString sql;
	sql.Format("select * from poemlearnedtable where num = '%s' and id = %d",m_num,m_id);
	record.CreateInstance(__uuidof(Recordset));
	record->Open(_bstr_t(sql),connection.GetInterfacePtr(),adOpenDynamic,adLockOptimistic,adCmdText);
	

	if(!record->adoEOF)
	{
		m_ustand = (char *)(bstr_t)record->GetCollect("undertanding");
		m_comment = (char *)(bstr_t)record->GetCollect("comment");
		if(m_comment != "")
			m_comment = "*******你已经评价过了!";
		UpdateData(false);
	}
	else
		MessageBox("没有此条记录!");}
	catch(_com_error e)
	{
		MessageBox(e.Description());
	}
	record->Close();


上面的代码捕捉到异常:在对应所需名称或序数的集合中,未找到项目
原因:在获取某字段内容时,字段名拼写错误o(╯□╰)o【undertanding应该是understanding】
=====================================================================
第二个
=====================================================================
m_comment = (char *)(bstr_t)record->GetCollect("comment");

如果记录集中某个记录的comment字段内容为空,会引起程序“Debug Error”,停止运行
我的解决办法:只能让comment的默认值改成“无”了

猜你喜欢

转载自niuyiwen.iteye.com/blog/2223631