CCommand::Close
釋放存取子資料列集與命令。
void Close( );
備註
命令使用一個資料列集、結果集存取子和 (選擇性) 參數存取子 (不同於資料表,不支援參數,而且不需要參數存取子)。
當您執行命令時,您應該在命令之後呼叫 Close 和 ReleaseCommand 。
當您要重複時執行相同的命令,您也應該呼叫 Close 以釋放每個結果集存取子在呼叫 Execute之前。 本系列的最後,您也應該呼叫 ReleaseCommand以釋放參數存取子。 另一個常見案例呼叫具有輸出參數的預存程序。 在許多提供者 (例如 SQL Server 的 OLE DB 提供者) 輸出參數值無法存取,直到您關閉結果集的存取子。 呼叫 Close 時傳回的資料列集和結果集,存取子,但不是參數存取子,因此可讓您擷取輸出參數的值。
範例
下列範例顯示當您重複地執行相同的命令時,呼叫 Close 和 ReleaseCommand。
void DoCCommandTest()
{
HRESULT hr;
hr = CoInitialize(NULL);
CCustomer rs; // Your CCommand-derived class
rs.m_BillingID = 6611; // Open billing ID 6611
hr = rs.OpenAll(); // (Open also executes the command)
hr = rs.MoveFirst(); // Move to the first row and print it
_tprintf_s(_T("First name: %s, Last Name: %s, Customer ID: %d, Postal Code: %s\n"),
rs.m_ContactFirstName, rs.m_L_Name, rs.m_CustomerID, rs.m_PostalCode);
// Close the first command execution
rs.Close();
rs.m_BillingID = 3333; // Open billing ID 3333 (a new customer)
hr = rs.Open(); // (Open also executes the command)
hr = rs.MoveFirst(); // Move to the first row and print it
_tprintf_s(_T("First name: %s, Last Name: %s, Customer ID: %d, Postal Code: %s\n"),
rs.m_ContactFirstName, rs.m_L_Name, rs.m_CustomerID, rs.m_PostalCode);
// Close the second command execution;
// Instead of the two following lines
// you could simply call rs.CloseAll()
// (a wizard-generated method):
rs.Close();
rs.ReleaseCommand();
CoUninitialize();
}
需求
標題: atldbcli.h