CRecordset::FlushResultSet

BOOL FlushResultSet () const;
gettare (CDBException);

Valore restituito

Diverso da zero se non ci sono più gruppi di risultati da recuperare; in caso contrario 0.

Osservazioni

Chiamare questa funzione membro per recuperare il prossimo set di risultati di una query (stored procedure), se non ci sono più gruppi di risultati. Solo quando si è completamente finito con il cursore sul set di risultati corrente, è necessario chiamare FlushResultSet . Si noti che quando si recupera risultato successivo tramito una chiamata FlushResultSet, il cursore non è valido su che del set di risultati; dovrebbe chiamare la funzione membro MoveNext dopo FlushResultSet.

Se una query utilizza un parametro di output o i parametri di input/output, è necessario chiamare FlushResultSet fino a quando essa restituisce FALSE (il valore 0), al fine di ottenere questi valori di parametro.

FlushResultSet chiama la funzione API ODBC SQLMoreResults. Se SQLMoreResults restituisce SQL_ERROR o SQL_INVALID_HANDLE, FlushResultSet genererà un'eccezione. Per ulteriori informazioni su SQLMoreResults, vedere ODBC SDK Programmer di riferimento.

Esempio

Il codice seguente si presuppone che COutParamRecordset è un CRecordset-oggetto derivato basato su una query con un parametro di input e un parametro di output e avendo più set di risultati. Eseguire l'override di nota la struttura della DoFieldExchange.

// DoFieldExchange override
//
// Only necessary to handle parameter bindings.
// Don't use CRecordset-derived class with bound
// fields unless all result sets have same schema
// OR there is conditional binding code.

void COutParamRecordset::DoFieldExchange( CFieldExchange* pFX )
{
   pFX->SetFieldType( CFieldExchange::outputParam );
   RFX_Long( pFX, "Param1", m_nOutParamInstructorCount );
         // The "Param1" name here is a dummy name 
         // that is never used

   pFX->SetFieldType( CFieldExchange::inputParam );
   RFX_Text( pFX, "Param2", m_strInParamName );
         // The "Param2" name here is a dummy name 
         // that is never used

}


// Now implement COurParamRecordset.

// Assume db is an already open CDatabase object
COutParamRecordset rs( &db );
rs.m_strInParamName = _T("Some_Input_Param_Value");

// Get the first result set
// NOTE: SQL Server requires forwardOnly cursor 
//       type for multiple rowset returning stored 
//       procedures
rs.Open( CRecordset::forwardOnly, 
         "{? = CALL GetCourses( ? )}", 
         CRecordset::readOnly);

// Loop through all the data in the first result set
while ( !rs.IsEOF( ) )
{
   CString strFieldValue;
   for( int nIndex = 0; 
        nIndex < rs.GetODBCFieldCount( ); 
        nIndex++ )
   {
      rs.GetFieldValue( nIndex, strFieldValue );

      // TO DO: Use field value string.
   }
   rs.MoveNext( );
}

// Retrieve other result sets...
while( rs.FlushResultSet( ) )
{
   // must call MoveNext because cursor is invalid
   rs.MoveNext( );

   while ( !rs.IsEOF( ) )
   {
      CString strFieldValue;
      for( int nIndex = 0; 
           nIndex < rs.GetODBCFieldCount( ); 
           nIndex++ )
      {
         rs.GetFieldValue( nIndex, strFieldValue );

         // TO DO: Use field value string.
      }
      rs.MoveNext( );
   }
}


// All result sets have been flushed. Cannot
// use the cursor, but the output parameter,
// m_nOutParamInstructorCount, has now been written.
// Note that m_nOutParamInstructorCount not valid until
// CRecordset::FlushResultSet has returned FALSE,
// indicating no more result sets will be returned.

// TO DO: Use m_nOutParamInstructorCount

// Cleanup
rs.Close( );
db.Close( );

Pa&noramica CRecordset |nbsp; Membri della classe | Gerarchia Chart

Vedere a&nchenbsp;CFieldExchange:: SetFieldType

Index