CRecordset::FlushResultSet
如果有多個結果集,擷取下一個結果集預先定義查詢 (預存程序)。
BOOL FlushResultSet( );
傳回值
不是零,如果有其他的結果集擷取;則為 0。
備註
只有在您完成與目前結果集時,的資料指標 (Cursor) 應該呼叫 FlushResultSet 。請注意,當您擷取呼叫設定的下一個結果 FlushResultSet,將游標不適用於該結果集;您應該在呼叫之後呼叫 FlushResultSetMoveNext 成員函式。
如果預先定義的查詢會使用輸出參數或輸出參數,您必須呼叫 FlushResultSet ,直到它傳回 FALSE (0 值),以取得這些參數的值。
FlushResultSet 呼叫 ODBC API 函式 SQLMoreResults。如果 SQLMoreResults 傳回 SQL_ERROR 或 SQL_INVALID_HANDLEFlushResultSet ,則會擲回例外狀況。如需 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