VC 向SQL里面添加记录 编译没问题 运行时在我向界面里面输入社团注册信息确定后就出错 下面是我的社团表 下面是表属性 哪里有问题啊 不明白void CADODemoView::OnSocietyRegister()
{
// TODO: Add your command handler code here
/*CSocietyRegDlg是社团注册的界面,m_strName是社团名对应的变量,m_Desc是社团描述,m_strChief是会长*/
CSocietyRegDlg SocietyRegDlg;
if(IDOK == SocietyRegDlg.DoModal())
{
UpdateData(TRUE);
if(!SocietyRegDlg.m_strName.GetLength())
{
AfxMessageBox("社团名不能为空!");
}
else
{
m_recordset->Close();
CString szSQl="SELECT * FROM 社团 where 名称='"+SocietyRegDlg.m_strName+"'";
try
{
m_recordset->Open((_variant_t)szSQl,_variant_t((IDispatch*)m_connection,true), adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_recordset->adoEOF)
{
m_recordset->Close();
AfxMessageBox("社团已经存在!");
return;
}
m_recordset->AddNew();
m_recordset->PutCollect("名称",_variant_t(SocietyRegDlg.m_strName));
m_recordset->PutCollect("描述",_variant_t(SocietyRegDlg.m_Desc));
m_recordset->PutCollect("会长",_variant_t(SocietyRegDlg.m_strChief));
CString strValue;
CTime time = CTime::GetCurrentTime();
strValue = time.Format("%Y-%m-%d");
m_recordset->PutCollect("入会时间",_variant_t(strValue));
m_recordset->Update();
AfxMessageBox("社团添加成功!");
}
catch(_com_error &e)
{
MessageBox(e.ErrorMessage());
return ;
}
}
}
}
BOOL CSocietyRegDlg::OnInitDialog()
{
CDialog::OnInitDialog();// TODO: Add extra initialization herereturn TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
{
// TODO: Add your command handler code here
/*CSocietyRegDlg是社团注册的界面,m_strName是社团名对应的变量,m_Desc是社团描述,m_strChief是会长*/
CSocietyRegDlg SocietyRegDlg;
if(IDOK == SocietyRegDlg.DoModal())
{
UpdateData(TRUE);
if(!SocietyRegDlg.m_strName.GetLength())
{
AfxMessageBox("社团名不能为空!");
}
else
{
m_recordset->Close();
CString szSQl="SELECT * FROM 社团 where 名称='"+SocietyRegDlg.m_strName+"'";
try
{
m_recordset->Open((_variant_t)szSQl,_variant_t((IDispatch*)m_connection,true), adOpenDynamic,adLockOptimistic,adCmdText);
if(!m_recordset->adoEOF)
{
m_recordset->Close();
AfxMessageBox("社团已经存在!");
return;
}
m_recordset->AddNew();
m_recordset->PutCollect("名称",_variant_t(SocietyRegDlg.m_strName));
m_recordset->PutCollect("描述",_variant_t(SocietyRegDlg.m_Desc));
m_recordset->PutCollect("会长",_variant_t(SocietyRegDlg.m_strChief));
CString strValue;
CTime time = CTime::GetCurrentTime();
strValue = time.Format("%Y-%m-%d");
m_recordset->PutCollect("入会时间",_variant_t(strValue));
m_recordset->Update();
AfxMessageBox("社团添加成功!");
}
catch(_com_error &e)
{
MessageBox(e.ErrorMessage());
return ;
}
}
}
}
BOOL CSocietyRegDlg::OnInitDialog()
{
CDialog::OnInitDialog();// TODO: Add extra initialization herereturn TRUE; // return TRUE unless you set the focus to a control
// EXCEPTION: OCX Property Pages should return FALSE
}
m_recordset->PutCollect("入会时间",_variant_t(strValue));
这两个地方的字段名与表不符 太粗心了