关于修改记录的问题,高分求助 我把一个用ACCESS创建的数据库在对话框中用ListCtrl控件显示,现在想选中一条记录后,按“修改”按钮,弹出一个对话框,对话框可以看到目前这条记录的信息,在对话框中修改完成后,数据库和ListCtrl中的相应记录也修改。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 void CDBDialog::OnInfomodify() { // TODO: Add your control notification handler code here UpdateData(TRUE); int nSelCount = m_listinfo.GetSelectedCount(); if (nSelCount <= 0) { AfxMessageBox("请选择修改项!",MB_OK|MB_ICONEXCLAMATION); return; }; CDBInfoModifyDlg dlg; dlg.m_infoid = m_PatientInfoRecordset1.m_id; dlg.m_infoname = m_PatientInfoRecordset1.m_name; dlg.m_infosex = m_PatientInfoRecordset1.m_sex; dlg.m_infoage = m_PatientInfoRecordset1.m_age; dlg.m_infolr = m_PatientInfoRecordset1.m_lr ; UpdateData(FALSE); if(dlg.DoModal() != IDOK) return; try{ m_PatientInfoRecordset1.Edit(); m_PatientInfoRecordset1.m_id = dlg.m_infoid; m_PatientInfoRecordset1.m_name = dlg.m_infoname; m_PatientInfoRecordset1.m_sex = dlg.m_infosex; m_PatientInfoRecordset1.m_age= dlg.m_infoage; m_PatientInfoRecordset1.m_lr = dlg.m_infolr ; if(m_PatientInfoRecordset1.CanUpdate()) { m_PatientInfoRecordset1.Update(); } } catch(CDaoException *exception) { exception->ReportError(); m_PatientInfoRecordset1.MoveNext(); m_PatientInfoRecordset1.MovePrev(); return; } m_PatientInfoRecordset1.Update(); m_PatientInfoRecordset.Close(); m_PatientInfoRecordset.Open(); ShowAllData();}我用这段代码,结果每次弹出的对话框都是显示的列表中的最后一条记录,而且也修改不成功。为什么呢?大家一定要帮我啊!! CDBInfoModifyDlg dlg; m_PatientInfoRecordset1.Move(????); dlg.m_infoid = m_PatientInfoRecordset1.m_id; dlg.m_infoname = m_PatientInfoRecordset1.m_name; dlg.m_infosex = m_PatientInfoRecordset1.m_sex; dlg.m_infoage = m_PatientInfoRecordset1.m_age; dlg.m_infolr = m_PatientInfoRecordset1.m_lr ; UpdateData(FALSE);////////////////////去掉 if(dlg.DoModal() != IDOK) return; try{ m_PatientInfoRecordset1.Edit(); m_PatientInfoRecordset1.m_id = dlg.m_infoid; m_PatientInfoRecordset1.m_name = dlg.m_infoname; m_PatientInfoRecordset1.m_sex = dlg.m_infosex; m_PatientInfoRecordset1.m_age= dlg.m_infoage; m_PatientInfoRecordset1.m_lr = dlg.m_infolr ; //if(m_PatientInfoRecordset1.CanUpdate()) //{ m_PatientInfoRecordset1.Update(); //} } catch(CDaoException *exception) { exception->ReportError(); m_PatientInfoRecordset1.MoveNext(); m_PatientInfoRecordset1.MovePrev(); return; } dfyang:我按照你的方法可以在对话框中显示记录信息,而且可以修改,可是并不是我选中的记录啊?!这是Move的那段代码,int nItem;POSITION pos = m_listinfo.GetFirstSelectedItemPosition();nItem = m_listinfo.GetNextSelectedItem(pos);m_PatientInfoRecordset1.MoveFirst(); m_PatientInfoRecordset1.Move(nItem);我跟踪调试,也没有发现什么规律,不知道这段代码哪里有问题,哪位大侠一定要帮帮我这个菜鸟啊 不能直接使用clist中的序号来对应数据库中记录的顺序的(会乱的),最好是在每个item中记录下对应的记录的一些关键key,再用这些关键key来决定是对应哪一条记录,实现上比较复杂。 我在数据库里直接搜索, int nItem = GetSelecteListItem();//得到选中的行 CString str = m_listinfo.GetItemText(nItem,0); CString strSql; strSql = "SELECT * FROM PatientInfo WHERE Id = '"+str+"'"; m_PatientInfoRecordset1.Close(); m_PatientInfoRecordset1.Open(AFX_DAO_USE_DEFAULT_TYPE,strSql,0);再接CDBInfoModifyDlg dlg; dlg.m_infoid = m_PatientInfoRecordset1.m_id; dlg.m_infoname = m_PatientInfoRecordset1.m_name; dlg.m_infosex = m_PatientInfoRecordset1.m_sex; dlg.m_infoage = m_PatientInfoRecordset1.m_age; dlg.m_infolr = m_PatientInfoRecordset1.m_lr ;。可是提示Too few parameters.Expected 1.,再点就终止调试了。这是我在一个例子里看到的,他是在同一个对话框里显示记录和修改记录,我就调用了一个对话框,就出问题了,为什么啊 int i=m_list.GetSelectionMark(); if(i==-1) MessageBox("请选择选项!","请选择选项...",MB_OK|MB_ICONSTOP); else{你的操作}用下面的函数来确定你所选准的项int m_list.GetSelectionMark()函数的返回值是你所选准的行!!!! 然后用dlg.m_infoid =m_list.GetItemText(i,x);来给值x为列号 在VisualC++中显示自定义数据类型(神) 模板有何具体作用? 公司要招人,特向各位大牛征集VC笔试题和面试题!!!有的速报! ADO 中,Delete(adAffectCurrent)成功,而Delete(adAffectAll)失败,请问这是为什么? C sdk程序,但运行时窗口只能点击上面的两个按纽,其它连窗口都无法聚焦.帮忙看看. 如何快速得到一个节点下所有的机器IP 一个特傻的问题:怎么我的DLL不能Debug了? ODBC 数据库查询更新问题 (急) 散分 数据包的分片与重组 简单的行编辑器纠错,不知道怎么解决 求mfc的界面设计资料 可以只有.h文件和.lib文件吗?
{
// TODO: Add your control notification handler code here
UpdateData(TRUE);
int nSelCount = m_listinfo.GetSelectedCount();
if (nSelCount <= 0)
{
AfxMessageBox("请选择修改项!",MB_OK|MB_ICONEXCLAMATION);
return;
}; CDBInfoModifyDlg dlg;
dlg.m_infoid = m_PatientInfoRecordset1.m_id;
dlg.m_infoname = m_PatientInfoRecordset1.m_name;
dlg.m_infosex = m_PatientInfoRecordset1.m_sex;
dlg.m_infoage = m_PatientInfoRecordset1.m_age;
dlg.m_infolr = m_PatientInfoRecordset1.m_lr ;
UpdateData(FALSE);
if(dlg.DoModal() != IDOK)
return;
try{
m_PatientInfoRecordset1.Edit();
m_PatientInfoRecordset1.m_id = dlg.m_infoid;
m_PatientInfoRecordset1.m_name = dlg.m_infoname;
m_PatientInfoRecordset1.m_sex = dlg.m_infosex;
m_PatientInfoRecordset1.m_age= dlg.m_infoage;
m_PatientInfoRecordset1.m_lr = dlg.m_infolr ;
if(m_PatientInfoRecordset1.CanUpdate())
{
m_PatientInfoRecordset1.Update();
}
}
catch(CDaoException *exception)
{
exception->ReportError();
m_PatientInfoRecordset1.MoveNext();
m_PatientInfoRecordset1.MovePrev();
return;
}
m_PatientInfoRecordset1.Update();
m_PatientInfoRecordset.Close();
m_PatientInfoRecordset.Open();
ShowAllData();
}我用这段代码,结果每次弹出的对话框都是显示的列表中的最后一条记录,而且也修改不成功。
为什么呢?大家一定要帮我啊!!
m_PatientInfoRecordset1.Move(????);
dlg.m_infoid = m_PatientInfoRecordset1.m_id;
dlg.m_infoname = m_PatientInfoRecordset1.m_name;
dlg.m_infosex = m_PatientInfoRecordset1.m_sex;
dlg.m_infoage = m_PatientInfoRecordset1.m_age;
dlg.m_infolr = m_PatientInfoRecordset1.m_lr ;
UpdateData(FALSE);////////////////////去掉
if(dlg.DoModal() != IDOK)
return;
try{
m_PatientInfoRecordset1.Edit();
m_PatientInfoRecordset1.m_id = dlg.m_infoid;
m_PatientInfoRecordset1.m_name = dlg.m_infoname;
m_PatientInfoRecordset1.m_sex = dlg.m_infosex;
m_PatientInfoRecordset1.m_age= dlg.m_infoage;
m_PatientInfoRecordset1.m_lr = dlg.m_infolr ;
//if(m_PatientInfoRecordset1.CanUpdate())
//{
m_PatientInfoRecordset1.Update();
//}
}
catch(CDaoException *exception)
{
exception->ReportError();
m_PatientInfoRecordset1.MoveNext();
m_PatientInfoRecordset1.MovePrev();
return;
}
这是Move的那段代码,
int nItem;
POSITION pos = m_listinfo.GetFirstSelectedItemPosition();
nItem = m_listinfo.GetNextSelectedItem(pos);m_PatientInfoRecordset1.MoveFirst();
m_PatientInfoRecordset1.Move(nItem);
我跟踪调试,也没有发现什么规律,不知道这段代码哪里有问题,哪位大侠一定要帮帮我这个菜鸟啊
int nItem = GetSelecteListItem();//得到选中的行
CString str = m_listinfo.GetItemText(nItem,0);
CString strSql;
strSql = "SELECT * FROM PatientInfo WHERE Id = '"+str+"'";
m_PatientInfoRecordset1.Close();
m_PatientInfoRecordset1.Open(AFX_DAO_USE_DEFAULT_TYPE,strSql,0);
再接
CDBInfoModifyDlg dlg;
dlg.m_infoid = m_PatientInfoRecordset1.m_id;
dlg.m_infoname = m_PatientInfoRecordset1.m_name;
dlg.m_infosex = m_PatientInfoRecordset1.m_sex;
dlg.m_infoage = m_PatientInfoRecordset1.m_age;
dlg.m_infolr = m_PatientInfoRecordset1.m_lr ;。
可是提示Too few parameters.Expected 1.,再点就终止调试了。这是我在一个例子里看到的,他是在同一个对话框里显示记录和修改记录,我就调用了一个对话框,就出问题了,为什么啊
if(i==-1)
MessageBox("请选择选项!","请选择选项...",MB_OK|MB_ICONSTOP);
else
{你的操作}
用下面的函数来确定你所选准的项
int m_list.GetSelectionMark()函数的返回值是你所选准的行!!!!