我用ODBC连接一个数据库,要将其中一个表的记录读到一个结构中去。
  代码如下
  while(!rsStudentRec.IsEOF() && !rsStudentRec.IsBOF())
  { 
    .......将记录加进结构
   rsStudentRec.MoveNext();  }
  表中记录不多,但是程序会没有响应,仿佛进入了死循环。。
  请问遍历一个表用这种方法对吗?

解决方案 »

  1.   

    if(!rsStudentRec.IsOpen())
       rsStudentRec.Open();
    while(!rsStudentRec.IsEOF()) 
    {
       deal with
       rsStudentRec.MoveNext()
    }
    如果你的表读取没有什么错误的话,就没有什么错误!如果在有什么错误,就肯定是你的表处理有问题!你不妨用debug来但不调试看一下。祝好运!
      

  2.   

    if(!rsStudentRec.IsOpen() )
        rsStudentRec.Open() ;
    while(!rsStudentRec.IsEOF() )
      {
      deal with
      rsStudentRec.MoveNext()
    }这样如果你的表读取和处理没有问题的话,就应该没有问题了。如果有问题的话,你可以用debug来但不调试。祝你好运。
      

  3.   

    while(!rsStudentRec.IsEOF() && !rsStudentRec.IsBOF())这个循环好像退不出去吧?
      

  4.   

    Here is an example for the using of IsBof and IsEof,
    Wish it helpful to you :)// Open a recordset; first record is current
    CCustSet rsCustSet( NULL );
    rsCustSet.Open( );if( rsCustSet.IsBOF( ) )
        return;
        // The recordset is empty// Scroll to the end of the recordset, past
    // the last record, so no record is current
    while ( !rsCustSet.IsEOF( ) )
        rsCustSet.MoveNext( );// Move to the last record
    rsCustSet.MoveLast( );// Scroll to beginning of the recordset, before
    // the first record, so no record is current
    while( !rsCustSet.IsBOF( ) )
        rsCustSet.MovePrev( );// First record is current again
    rsCustSet.MoveFirst( );