我的过程如下:文件->新建->工程->MFC AppWizard[exe]->基本对话框->Finish ,
出现窗口后,我把新窗口的“确定”“取消”按钮删除,自己从右边的树条中添加了俩Editbox,一Button,我在Button的属性里把它的ID改为IDC_OK,然后连接数据库,我又用ClassWizard新建了一CRecordSet的派生类CLoginSet,又双击Button,写了如下代码
CLoginSet *m_recordset=new CLoginSet(&m_database);
CString strSQL;
m_recordset.Open(strSQL);
UpdateData(true);
strSQL.Format("select * from user_pswd where tms_user='%s' and tms_pswd='%s'",m_username,m_password);
m_recordset->Open(AFX_DB_USE_DEFAULT_TYPE,strSQL);
if(m_recordset->GetRecordCount()==0){
if(count<3){
MessageBox("Login incorrect!");
count++;
}
else{
MessageBox("too many trials");
m_database.Close();
CDialog::OnOK();
}
}
else{
m_database.Close();
user.Format("%s",m_username);
CMainDlg m_Main;
m_Main.user.Format("%s",m_username);
m_Main.m_database.Open(_T("database"));
m_Main.DoModal();
CDialog::OnOK();
}