CRecordset::FlushResultSet

Recupera il set di risultati seguente query già definita (stored procedure), se esistono più set di risultati.

BOOL FlushResultSet( );

Valore restituito

Diverso da zero se esistono più set di risultati da recuperare, in caso contrario 0.

Note

È necessario chiamare FlushResultSet solo quando completamente il termine del cursore nel set di risultati corrente.Si noti che quando si recupera il set di risultati seguente chiamando FlushResultSet, il cursore non è valido nel gruppo di risultati, chiamare la funzione membro MoveNext dopo aver chiamato FlushResultSet.

Se una query già definita utilizza un parametro di output o parametri di input/output, è necessario chiamare FlushResultSet finché non restituiscono FALSE (il valore 0), per ottenere i valori del parametro.

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

La stored procedure deve contenere campi associati se si desidera chiamare FlushResultSet.

Eccezioni

Questo metodo può generare eccezioni di tipo CDBException*.

Esempio

Il codice seguente presuppone che COutParamRecordset sia CRecordsetoggetto derivato da in base a una query già definita con un parametro di input e un parametro di output e avere più set di risultati.Si noti la struttura di override 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 CCourses::DoFieldExchange(CFieldExchange* pFX)
{
   pFX->SetFieldType(CFieldExchange::outputParam);
   RFX_Long(pFX, _T("Param1"), m_nCountParam);
      // The "Param1" name here is a dummy name 
      // that is never used

   pFX->SetFieldType(CFieldExchange::inputParam);
   RFX_Text(pFX, _T("Param2"), m_strNameParam);
      // The "Param2" name here is a dummy name 
      // that is never used
}
// Assume db is an already open CDatabase object
CCourses rs(&m_dbCust);
rs.m_strNameParam = _T("History");

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

// Loop through all the data in the first result set
while (!rs.IsEOF())
{
   CString strFieldValue;
   for(short 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(short 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_nCountParam, has now been written.
// Note that m_nCountParam is not valid until
// CRecordset::FlushResultSet has returned FALSE,
// indicating no more result sets will be returned.

// TO DO: Use m_nCountParam

// Cleanup
rs.Close();

Requisiti

intestazione: afxdb.h

Vedere anche

Riferimenti

Classe di CRecordset

Grafico della gerarchia

CFieldExchange::SetFieldType