void CDlgRegister::OnBRegister() 
{
// TODO: Add your control notification handler code here
UpdateData(true);
if(m_strName.IsEmpty()||m_strPwd.IsEmpty()||m_strRePwd.IsEmpty())
{
MessageBox("您还有未填写的信息!");
}
else if(m_strPwd!=m_strRePwd)
{
MessageBox("请您再确认一下你的密码!");
}
else
{
CString sql="SELECT * FROM [user] where username='"+m_strName+"'";
try
{
m_pRecordset.CreateInstance("ADODB.RecordSet");
m_pRecordset->Open((_variant_t)sql,_variant_t((IDispatch*)theApp.m_pConnection,true),adOpenStatic,adLockOptimistic,adCmdText); if(m_pRecordset->adoEOF)
{
try
{
_variant_t RecordsAffected;
theApp.m_strSQL=INSERT INTO user(username,password) VALUES('"+m_strName+"','"+m_strPwd+"');
theApp.m_pConnection->Execute((_bstr_t)theApp.m_strSQL,&RecordsAffected,adCmdText);
CDialog::OnOK();
CDlgMain dlgMain;
dlgMain.DoModal();
}
catch(_com_error e)
{
CATCH_ERROR;
return;
}
}
else
{
MessageBox("这个用户名已经被注册,请重新注册!");
}
}
catch(_com_error e)
{
CATCH_ERROR;
return;
}
}
} 然后在执行时,异常处理抱如下错误:     错误编号:80040e14
     错误信息:IDispatch error #3092
     错误源:Microsoft JET Database Engine
     错误描述:INSERT INTO 语句的语法错误可是我看了,这句语法没有错误啊....请各位大虾帮帮忙.....

解决方案 »

  1.   

    稍微更正一下:theApp.m_strSQL=INSERT INTO user(username,password) VALUES('"+m_strName+"','"+m_strPwd+"');
    改为:theApp.m_strSQL="INSERT INTO user(username,password) VALUES('"+m_strName+"','"+m_strPwd+"')";请问到底是哪里的问题啊????
      

  2.   

    如果程序没问题,就应该是 SQL 语法错误,把字段加上[]试试。theApp.m_strSQL.Format( 
        "INSERT INTO [user] ([username],[password]) VALUES ('%s','%s')", 
        m_strName, m_strPwd
    );
      

  3.   

    字段的名字就象 C 关键字,在 SQL 语句中不能使用。