C++中连接ACCESS的问题

来源:百度知道 编辑:UC知道 时间:2024/09/20 21:14:44
void CDEMOView::TestEnd()
{
// TODO: Add your command handler code here
m_bTestBegin=FALSE;
m_bTestRead=FALSE;
KillTimer(2);
CString strTestScore;
strTestScore.Format("此次测试成绩为:%d个字符/分钟",inputRight*60/m_lTestTime);
strNoteMessage="就绪";
if(MessageBox(strTestScore,"打字测试系统",MB_YESNO)==IDNO)
{
Invalidate();
return;
}
Invalidate();
_variant_t vUserId,vTestDate,vSpeed,vRight,vWrong;
_variant_t vPercent,vTestTime,vTestFile,vEndTestTime;
_RecordsetPtr m_pRecordset;
CString m_strSql;
m_strSql="SELECT*FROM scorer";
m_pRecordset.CreateInstance("ADODB.Recordset");

try
{
m_pRecordset->Open((_variant_t)m_strSql,_variant_t((IDispatch *)theApp.m_pConnection,true),
adOpenStatic,adLockOptimistic,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox("读取数据库失败!");
}

m_pRecordset->AddNew(

1.有没有导入 #import "msado15.dll" rename_namespace("ADOCG") rename("EOF", "EndOfFile")
2.有没有 进行 数据库的连接
Sql.Format("Provider=Microsoft.Jet.OLEDB.4.0;Data Source = XH.mdb");

以上代码看不出什么 问题,不知道是不是逻辑问题,你在这个函数 设置个断点跟下,看是哪里出了问题