提示unhandled exception in 222.exe (NTDLL.DLL);0xc0000005;Access Violation
CDatabase m_database; CString username; CString password; CString id; m_database.Open(NULL,FALSE,FALSE,_T("ODBC;Dsn=student;server=localhost;uid=;pwd=")); CString strSQL; strSQL.Format ("select * from user_pass where username='%s'and password='%s' and id='%s' ",m_username,m_password,m_id); int len = m_ListTeacher.GetHeaderCtrl()->GetItemCount(); try{ m_pSet->MoveFirst(); int nItem=m_ListTeacher.GetItemCount (); while (!m_pSet->IsEOF()) { username=m_pSet->m_username1; password=m_pSet->m_password1; id=m_pSet->m_id1; m_ListTeacher.InsertItem(nItem,""); m_ListTeacher.SetItemText(nItem,2,username); m_ListTeacher.SetItemText(nItem,1,password); m_ListTeacher.SetItemText(nItem,0,id); m_pSet->MoveNext(); nItem ++; } } catch(_com_error e) { AfxMessageBox("表中存在记录为空!"); return; } m_pSet->Close();//关闭记录 }5void CMy222Dlg::OnButton2() { // TODO: Add your control notification handler code here CDatabase m_database; CLoginSet* m_recordset=new CLoginSet (&m_database); CString strSQL; UpdateData(TRUE); strSQL.Format ("select * from user_pass where username='%s'and password='%s' ",m_username,m_password); m_recordset->Open (AFX_DB_USE_DEFAULT_TYPE,strSQL); if(m_recordset->GetRecordCount()==0) MessageBox("密码错误",NULL,MB_OK); else MessageBox("登陆成功",NULL,MB_OK);
try{//你的数据库代码代码}catch (_com_error& e){CString strMsg;strMsg.Format(_T("错误描述:%s\n错误消息%s", (LPCTSTR)e.Description(), (LPCTSTR)e.ErrorMessage());AfxMessageBox(strMsg);}catch(CException* pEx){pEx->ReportError();pEx->Delete();}
[解决办法]
应该是使用了没经过初始化的指针,访问到了系统内核了。