CCommand::Close
发布与命令关联的访问器 行集。
void Close( );
备注
命令使用一行集、结果集访问器和 (可选的) 参数访问器 (不同于不支持参数及不需要参数访问器的表)。
当执行命令,还应在命令之后调用 Close 和 ReleaseCommand。
在要重复执行同一命令时,您应在调用 Execute之前通过调用 Close 释放每个结果集访问器。 在序列末尾,应调用 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