FlushResultSet (BOOL) const;
lançar (CDBException);
Valor de retorno
Diferente de zero se houver mais conjuntos de resultados a serem recuperados; caso contrário 0.
Observações
Chame essa função de membro para recuperar o próximo conjunto de resultados de uma consulta predefinida (procedimento armazenado), se houver Múltiplo conjuntos de resultados. Você deve chamar FlushResultSet somente quando terminar completamente com o cursor sobre o conjunto de resultados atual. Observe que quando você recupera o Avançar resultado definir chamando FlushResultSet, o cursor não é válido no conjunto de resultados; Você deve chamar a função de membro MoveNext após a chamada FlushResultSet.
Se uma consulta predefinida usa um parâmetro de saída ou parâmetros de entrada/saída, você deve chamar FlushResultSet até que ele retorne FALSE (o valor 0), para obter esses valores de parâmetro.
FlushResultSet chama a API de ODBC função SQLMoreResults. Se SQLMoreResults retorna SQL_ERROR ou SQL_INVALID_HANDLE, FlushResultSet lançará uma exceção. Para obter mais informações sobre SQLMoreResults, consulte o Referência do programador ODBC SDK.
Exemplo
O código a seguir pressupõe que COutParamRecordset é um CRecordset-derivado objeto baseado em uma consulta predefinida com um parâmetro de entrada e um parâmetro de saída e tendo vários conjuntos de resultados. Observe a estrutura de DoFieldExchange substituir.
// 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( );
Visão geral de CRecordset | Membros de classe | Gráfico de hierarquia
Co&nsulte tambémnbsp;CFieldExchange:: SetFieldType