CRecordset::FlushResultSet

Const BOOL FlushResultSet ();
(CDBException) を投げる;

戻り値

0 以外の値がある場合より多くの結果セットを取得する;そうでなければ 0。

解説

複数の結果セットがある場合は、定義済みクエリ (ストアド プロシージャ) の次の結果セットを取得するにはこのメンバー関数を呼び出します。のみ、現在の結果セット上のカーソルを完全に終了するとFlushResultSetを呼び出す必要があります。FlushResultSetを呼び出してを設定、次の結果を取得すると、カーソル結果セットが有効でないことに注意してください。FlushResultSetを呼び出した後は、 MoveNextメンバ関数を呼び出す必要があります。

定義済みのクエリが出力パラメーターまたは入出力パラメーターを使用する場合、これらのパラメーター値をFALSE (0)、返しますまでFlushResultSetを呼び出す必要があります。

FlushResultSetは、ODBC API 関数指定して SQLMoreResultsを呼び出します。指定して SQLMoreResults SQL_ERRORまたはSQL_INVALID_HANDLEを返す場合は、 FlushResultSetは例外をスローします。指定して SQLMoreResultsの詳細については、 ODBC SDK programmer's Referenceを参照してください。

次のコードは、前提と COutParamRecordsetCRecordsetです-定義済みクエリは、入力パラメーターと出力パラメーター、および複数の結果セットを持つ派生オブジェクト。注構造、 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( );

CRecordset の概要|nbsp;クラス メンバー |階層図(&N)

参照特価;CFieldExchange::SetFieldType(&N)

Index