BOOL FlushResultSet นี้ const
โยน (CDBException);
ส่งกลับค่า
ไม่ใช่ศูนย์ถ้ามีชุดผลลัพธ์เพิ่มเติมถูกเรียก 0 อื่น?
หมายเหตุ
เรียกฟังก์ชันนี้สมาชิกในการเรียกชุดผลลัพธ์ถัดไปของแบบสอบถามล่วงหน้า (stored procedure), ถ้ามีชุดผลลัพธ์หลาย คุณควรเรียกFlushResultSetเมื่อคุณดำเนินการเสร็จสมบูรณ์ ด้วยเคอร์เซอร์ที่อยู่บนชุดผลลัพธ์ปัจจุบันเท่านั้น โปรดสังเกตว่า เมื่อคุณดึงข้อมูลผลลัพธ์ถัดไปตั้งค่าได้ โดยการโทรFlushResultSetเคอร์เซอร์ของคุณไม่ถูกต้องบนว่า ชุดผลลัพธ์ คุณควรเรียกใช้ฟังก์ชันMoveNextสมาชิกหลังจากโทรFlushResultSet?
ถ้าแบบสอบถามที่กำหนดไว้ล่วงหน้าใช้พารามิเตอร์แสดงผลหรือพารามิเตอร์อินพุต/เอาท์พุต คุณต้องเรียกFlushResultSetจนกว่าจะส่งกลับค่าเป็น FALSE (ค่า 0), เพื่อให้ได้ค่าพารามิเตอร์เหล่านี้?
FlushResultSetเรียกใช้ฟังก์ชัน ODBC API SQLMoreResults ถ้าSQLMoreResultsส่งกลับSQL_ERRORหรือSQL_INVALID_HANDLEแล้วFlushResultSetจะโยนข้อยกเว้น สำหรับข้อมูลเพิ่มเติมเกี่ยวกับSQLMoreResultsดูการอ้างอิงของ ODBC SDK Programmer?
ตัวอย่าง
รหัสต่อไปนี้สมมติที่ 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 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)
ดูเพิ่มเติมnbspCFieldExchange::SetFieldType(&N)