CRecordset::Update()出现非法的属性/标识符

离离源上草 2013-08-05 09:58:57

Access数据库插入一条新记录,更新出现的问题,求大神解救!!!在线等
功能代码如下:
void UserRegister::OnRegister()
{
// TODO: Add your control notification handler code here
UpdateData(true);
int index=m_userkind.GetCurSel();
CDatabase _db;
CDatabase m_db;
SQLConfigDataSource(NULL,
ODBC_ADD_DSN,
"Microsoft Access Driver (*.mdb)",
"DSN=user\0" "DBQ=dbf\\user.mdb\0" "DEFAULTDIR=dbf\0"); //注册本地数据库数据源,
m_db.OpenEx("DSN=user",CDatabase::noOdbcDialog);//user是数据源名称
CoInitialize(NULL);
if(!_db.OpenEx("DSN=user", CDatabase::openReadOnly|CDatabase::noOdbcDialog))
{
MessageBox("连接数据库失败!");
return;
}
CRecordset recordset(&_db);
CString strSQL="select * from userinfo where username='"+m_username+"'";
while(1)
{
if(!recordset.Open(CRecordset::dynaset,strSQL))
{
MessageBox("打开数据库失败!");
return;
}
int num=recordset.GetRecordCount();
if(num!=0)
{
MessageBox("该用户已注册,请更改用户名!");
return;
}
else
{
MySet myset(&_db);
strSQL="select * from userinfo";
if(!myset.Open(CRecordset::dynaset,strSQL))
return;
//注册信息加入数据库信息表
myset.AddNew();
myset.SetFieldNull(NULL);
myset.m_username=m_username;
myset.m_userpassword=m_userpassword;
myset.m_level=(long)index+1;
myset.Update();//??????
MessageBox("****");
myset.Close();
}
}
recordset.Close();
UpdateData(false);
}
...全文
297 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
离离源上草 2013-08-05
  • 打赏
  • 举报
回复
void CFactoryManagementDlg::OnLogin() { // TODO: Add your control notification handler code here UpdateData(true); SQLConfigDataSource(NULL, ODBC_ADD_DSN, "Microsoft Access Driver (*.mdb)", "DSN=user\0" "DBQ=dbf\\user.mdb\0" "DEFAULTDIR=dbf\0"); //注册本地数据库数据源 CoInitialize(NULL); CDatabase _db; CDatabase m_db; CRecordset m_rec(&_db); _db.OpenEx("DSN=user",CDatabase::noOdbcDialog);//user是数据源名称 if(!m_db.OpenEx("DSN=user", CDatabase::openReadOnly|CDatabase::noOdbcDialog)) { MessageBox("连接数据库失败!"); return; } CRecordset recordset(&m_db); CString strSQL="select * from userinfo where username='"+m_username+"' and userpassword='"+m_userpassword+"'"; if(!recordset.Open(CRecordset::dynaset,strSQL)) { MessageBox("打开数据库失败!"); return; } //MessageBox("####"); if(recordset.GetRecordCount()!=0) { ManagementMain dlg; dlg.DoModal(); } } 这是我的登录功能,成功执行完dlg.DoModal()。 问题在于CRecordset::Update()什么情况会弹出上图那个错误提示???求解呢
离离源上草 2013-08-05
  • 打赏
  • 举报
回复
我上一个登录操作查询用户也连接了数据库,也是用的SQLConfigDataSource()没有问题。
zgl7903 2013-08-05
  • 打赏
  • 举报
回复
SQLConfigDataSource 看返回值成功了么? dbf是多少? CDBException 捕捉异常

{
    if ( m_pSet != NULL )
        return m_pSet;        // Recordset already allocated

    m_pSet = new CSectionSet( NULL );
    try
    {
        m_pSet->Open( );
    }
    catch( CDBException* e )
    {
        AfxMessageBox( e->m_strError,   
                      MB_ICONEXCLAMATION );
        // Delete the incomplete recordset object
        delete m_pSet;
        m_pSet = NULL;
        e->Delete();
    }
    return m_pSet;
}

离离源上草 2013-08-05
  • 打赏
  • 举报
回复
我自己不知怎么改,没有注释你说的那句,也可以了……也谢谢你的解决方案了,我备份一下做个验证看看! 现在出了一个新问题: MySet myset(&m_db); strSQL="select * from userinfo"; if(!myset.Open(CRecordset::dynaset,strSQL)) return; //注册信息加入数据库信息表 //MessageBox("####"); myset.AddNew(); myset.SetFieldNull(NULL); myset.m_username=m_username; myset.m_userpassword=m_userpassword; myset.m_level=(long)index+1; myset.m_phone=m_phone; myset.Update(); myset.Requery(); myset.Close(); 执行到myset.Open(CRecordset::dynaset,strSQL)居然要弹出对话框提示选择数据源了??? SQLConfigDataSource是放在了主程序类的构造函数了的,为什么这里还要提示选择数据源呢?
zgl7903 2013-08-05
  • 打赏
  • 举报
回复
把这句屏蔽了 myset.SetFieldNull(NULL);

4,011

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 数据库
社区管理员
  • 数据库
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧