我用CRecordset派生CMyRecordset,与数据源绑定。数据源中的字段分别为CString name,COleDateTime timeStart,COleDateTime timeStop,int recordNum(索引);
CMyDlg::OnDelete()
{
...
CString str;
GetQuery(); //自定义函数,设置m_strFilter.
m_Recordset.Open();
//m_ListCtrl为列表控件,格式为report.用来显示记录。
for(int i=0;i<m_ListCtrl.GetItemCount();i++){
//列表控件上的条目为记录在数据源中的索引。由用户选择要删除的记录。
m_ListCtrl.GetItemText(i,0,str.GetBuffer(10),10);
m_Recordset.SetAbsolutePosition(atoi(str));
try{
m_Recordset.Delete(); //1
}
catch(CDBException *e){
AfxMessageBox(e->m_strError);
e->Delete();
m_Recordset.MoveFirst();
}
}
m_Recordset.Close();
...
}
执行到1出,就显示”操作失败,无当前记录“。可是查看m_Recordset的内容确实是要删除的记录。
用CRecordset的SetAbsolutePosition()不能引动记录指针吗?
CMyDlg::OnDelete()
{
...
CString str;
GetQuery(); //自定义函数,设置m_strFilter.
m_Recordset.Open();
//m_ListCtrl为列表控件,格式为report.用来显示记录。
for(int i=0;i<m_ListCtrl.GetItemCount();i++){
//列表控件上的条目为记录在数据源中的索引。由用户选择要删除的记录。
m_ListCtrl.GetItemText(i,0,str.GetBuffer(10),10);
m_Recordset.SetAbsolutePosition(atoi(str));
try{
m_Recordset.Delete(); //1
}
catch(CDBException *e){
AfxMessageBox(e->m_strError);
e->Delete();
m_Recordset.MoveFirst();
}
}
m_Recordset.Close();
...
}
执行到1出,就显示”操作失败,无当前记录“。可是查看m_Recordset的内容确实是要删除的记录。
用CRecordset的SetAbsolutePosition()不能引动记录指针吗?
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货