다음을 통해 공유


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

참고 항목

참조

CCommand 클래스

CCommand::ReleaseCommand