CRecordset::FlushResultSet

;如果有多个结果集,检索下一个结果集预定义查询(存储过程)。

BOOL FlushResultSet( );

返回值

非零,如果有多个结果集检索;否则为0。

备注

才会全部完成与设置时,的当前结果的光标应调用 FlushResultSet。 请注意,在检索调用设置的下一个结果 FlushResultSet,将光标无效的中的该结果;您应在调用 FlushResultSet之后调用 MoveNext 成员函数。

如果预定义查询使用一个输出参数或输入/输出参数,必须调用 FlushResultSet,直到返回 FALSE (值为0),以获取这些参数值。

FlushResultSet 调用ODBC API函数 SQLMoreResults。 如果 SQLMoreResults 返回 SQL_ERRORSQL_INVALID_HANDLE,则 FlushResultSet 将引发异常。 有关 SQLMoreResults的更多信息,请参见 Windows SDK。

如果要调用 FlushResultSet,您的存储过程需要绑定字段。

异常

此方法会引发类型 **CDBException***的异常。

示例

下面的代码假定,COutParamRecordset 是 CRecordset-根据与输入参数和输出参数和具有多个结果的预定义查询的派生对象设置。 请注意 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();

要求

标头: afxdb.h

请参见

参考

CRecordset选件类

层次结构图

CFieldExchange::SetFieldType