📄 subject_26734.htm
字号:
<p>
序号:26734 发表者:tudou 发表日期:2003-01-04 14:12:02
<br>主题:不懂怪了
<br>内容:为什么只能删除数据集的前两行,请大侠指点<BR>m_pSet->m_strFilter.Format("单号='%s'",m_pSet->m_Dh);<BR>m_pSet->Requery();<BR>m_pSet->MoveFirst();<BR>while(!m_pSet->IsEOF())<BR>{<BR> try{<BR> m_pSet->Delete();<BR> }<BR> catch(CDBException* e1){<BR> MessageBox("更新异常:\n"+e1->m_strError,"提示",MB_ICONEXCLAMATION);<BR> e1->Delete();<BR> m_pSet->m_pDatabase->Rollback();<BR> m_KcSet.m_pDatabase->Rollback();<BR> return;<BR> }<BR> m_pSet->MoveNext();<BR>}<BR>
<br><a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p>
<hr size=1>
<blockquote><p>
回复者:tudou 回复日期:2003-01-04 22:22:54
<br>内容:试出来了最后改为m_pSet->MoveFirst();
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tudou 回复日期:2003-01-06 19:18:38
<br>内容:有没有人告诉我为什么?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:萧马 回复日期:2003-01-07 14:15:42
<br>内容:删掉第一条,第二条记录理所当然成为第一条记录,这有什么疑问?
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tudou 回复日期:2003-01-09 17:08:50
<br>内容:我不懂的是为什么不管有多少条记录用movenext()都只能删除前两条<BR>而不是跳着删除<BR>观察执行中的m_pSet->m_lCurrentRecord(有四条记录)<BR>删除前 删除后 执行movenext后<BR> 0 -1 0<BR> 0 -1 -1 <-为什么不是0;是-1<BR>退出 <BR><BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:萧马 回复日期:2003-01-09 17:45:43
<br>内容:用delete是不需要update的,delete后数据库中马上删除该条记录,并将第二条记录变成第一条记录,以此类推.<BR>如果你想每次调用这个函数删除第一条记录,那么程序中的m_pSet->MoveNext();是没有必要的.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:旁观者 回复日期:2003-01-09 17:52:27
<br>内容:可能是你的变量m_lCurrentRecord有问题。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tudou 回复日期:2003-01-09 18:10:48
<br>内容:但是delete后set的游标不会自己指向第一条记录<BR>必须用move类的语句移动<BR>当然由于第二条记录变成第一条记录用movefirst可行<BR>但用movenext也应可行因为delete后为-1用movenext后为0<BR>可没试成<BR>(原先我也象萧马兄这样想,取掉movenext后就出现“没有当前记录的错误”)
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:旁观者 回复日期:2003-01-10 22:51:59
<br>内容:但是我用如下的代码可以成功删除所有查找出来的记录,我调试我自己的程序没有发现什么问题,是可行的。不过我不明白你的为什么不行,是不是你重载了移动记录的几个函数,函数里面代码有错误啊;或是用了什么特殊的排序……,你再仔细看看<BR>m_pSet->MoveFirst();<BR>while(!m_pSet->IsEOF())<BR>{<BR> m_pSet->Delete();<BR> m_pSet->MoveNext();<BR>}
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tudou 回复日期:2003-01-11 00:26:54
<br>内容:我曾经新建了一个工程<BR>试与旁观兄一样的代码<BR>也没过<BR>my god!不会是我的vc坏了吧
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:旁观者 回复日期:2003-01-11 15:41:22
<br>内容:如果可以的话,你可以把部分源代码附上,会有人帮你解决的,<BR>如果有时间我也可想看一下到底是什么问题。
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:萧马 回复日期:2003-01-11 23:54:38
<br>内容:同意!<BR>最好是将源码传上来,呵呵.
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:tudou 回复日期:2003-01-13 20:38:23
<br>内容:源代码很大上传不便<BR>以下是我在新建的数据库工程视图初始化函数的测试代码<BR>结果与我说的情况完全一样。<BR>void CTemView::OnInitialUpdate()<BR>{<BR> m_pSet = &GetDocument()->m_temSet;<BR> CRecordView::OnInitialUpdate();<BR> GetParentFrame()->RecalcLayout();<BR> ResizeParentToFit();<BR><BR> m_pSet->MoveFirst();<BR> while(!m_pSet->IsEOF())<BR> {<BR> m_pSet->Delete();<BR> m_pSet->MoveNext();<BR> }<BR><BR>}<BR>这个工程采用ODBC dynast数据源Access数据库<BR>这张表只有两个字段第一个为主键<BR>没有任何关联<BR><BR>二位仁兄有时间帮着琢磨琢磨<BR>有劳!!!有劳!!!!<BR><BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
回复者:骆驼之沙漠王子 回复日期:2003-01-13 21:01:43
<br>内容:void CTemView::OnInitialUpdate()<BR>{<BR> m_pSet = &GetDocument()->m_temSet;<BR> CRecordView::OnInitialUpdate();<BR> GetParentFrame()->RecalcLayout();<BR> ResizeParentToFit();<BR><BR> m_pSet->MoveFirst();<BR> while(!m_pSet->IsEOF())<BR> {<BR> m_pSet->Delete();<BR> }<BR><BR>}<BR>
<br>
<a href="javascript:history.go(-1)">返回上页</a><br><a href=http://www.copathway.com/cndevforum/>访问论坛</a></p></blockquote>
<hr size=1>
<blockquote><p>
<font color=red>答案被接受</font><br>回复者:旁观者 回复日期:2003-01-14 09:38:41
<br>内容:m_pSet打开后,得到的是所有记录吗,还是打开后查询出来的就只有几条?<BR>下面是MSDN里面的Acticle(没有做任何修改),虽然不是专门讲Delete的,但里面就有删除查找出来的所有记录的操作,希望对你有帮助:<BR><BR>This article explains how to perform a transaction in a recordset. <BR><BR>Note Only one level of transactions is supported; you cannot nest transactions.<BR><BR>To perform a transaction in a recordset <BR><BR>Call the CDatabase object’s BeginTrans member function. <BR><BR><BR>If you have not implemented bulk row fetching, call the AddNew/Update, Edit/Update, and Delete member functions of one or more recordset objects of the same database as many times as needed. See the article Recordset: Adding, Updating, and Deleting Records (ODBC). If you have implemented bulk row fetching, you must write your own functions to update the data source. For an example of how to do this, see the sampleDBFETCH.<BR><BR><BR>Finally, call the CDatabase object’s CommitTrans member function. Or if an error occurs in one of the updates, or you decide to cancel the changes, call its Rollback member function. <BR>The following example uses two recordsets to delete a student’s enrollment from a school registration database, removing the student from all classes in which the student is enrolled. The Delete calls in both recordsets must succeed, so a transaction is required. The example assumes the existence of m_dbStudentReg, a member variable of type CDatabase already connected to the data source, and the recordset classes CEnrollmentSet and CStudentSet. The strStudentID variable contains a value obtained from the user.<BR><BR>BOOL CEnrollDoc::RemoveStudent( CString strStudentID )<BR>{<BR> // remove student from all the classes<BR> // the student is enrolled in<BR><BR> if ( !m_dbStudentReg.BeginTrans( ) )<BR> return FALSE;<BR><BR> CEnrollmentSet rsEnrollmentSet(&m_dbStudentReg);<BR> rsEnrollmentSet.m_strFilter = "StudentID = " + strStudentID;<BR><BR> if ( !rsEnrollmentSet.Open(CRecordset::dynaset) )<BR> return FALSE;<BR><BR> CStudentSet rsStudentSet(&m_dbStudentReg);<BR> rsStudentSet.m_strFilter = "StudentID = " + strStudentID;<BR><BR> if ( !rsStudentSet.Open(CRecordset::dynaset) )<BR> return FALSE;<BR><BR> TRY<BR> {<BR> while ( !rsEnrollmentSet.IsEOF( ) )<BR> {<BR> rsEnrollmentSet.Delete( );<BR> rsEnrollmentSet.MoveNext( );<BR> }<BR><BR> // delete the student record<BR> rsStudentSet.Delete( );<BR><BR> m_dbStudentReg.CommitTrans( );<BR> }<BR><BR> CATCH_ALL(e)<BR> {<BR> m_dbStudentReg.Rollback( );<BR> return FALSE;<BR> }<BR> END_CATCH_ALL<BR><BR> rsEnrollmentSet.Close( );<BR> rsStudentSet.Close( );<BR><BR> return TRUE;<BR><BR>}<BR><BR>Warning Calling BeginTrans again without calling CommitTrans or Rollback is an error.<BR><BR><BR>2003-1-14 9:42:44
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -