방법: TableAdapter 쿼리 실행

TableAdapter 쿼리는 응용 프로그램에서 데이터베이스에 대해 실행할 수 있고 TableAdapter에 형식화된 메서드로 노출되는 SQL 문 또는 저장 프로시저입니다. 임의의 개체에 있는 임의의 메서드와 마찬가지로 연결된 메서드를 호출하여 TableAdapter 쿼리를 실행할 수 있습니다.

TableAdapter 쿼리는 데이터 테이블(Fill 및 FillBy 쿼리)을 채우거나 쿼리(GetData 및 GetDataBy 쿼리)에 의해 반환된 데이터로 채워진 새 데이터 테이블을 반환할 수 있습니다.

TableAdapter 쿼리 구성 마법사를 실행하여 기존 TableAdapter에 쿼리를 추가할 수 있습니다.

TableAdapter의 인스턴스 만들기

TableAdapter의 인스턴스를 만들어야 해당 메서드를 호출할 수 있습니다.

참고

TableAdapter는 데이터 집합 디자이너를 사용하여 만들고 편집하지만 데이터 집합 내의 중첩 클래스는 아닙니다. TableAdapter는 해당 TableAdapter와 연결된 데이터 집합 이름을 기준으로 식별되는 네임스페이스 내에 위치합니다. 명명 규칙은 DataSetName + "TableAdapter"입니다. 예를 들어, NorthwindDataSet과 연결된 모든 TableAdapter는 NorthwindDataSetTableAdapters 네임스페이스에 위치합니다. CustomersTableAdapter의 경우 정규화된 이름은 NorthwindDataSetTableAdapters.CustomersTableAdapter가 됩니다.

TableAdapter의 인스턴스를 만들려면

  • 데이터 소스 창에서 Windows 응용 프로그램의 폼으로 항목을 끌어 놓아 폼에 TableAdapter 인스턴스를 자동으로 만듭니다. 인스턴스의 이름을 보려면 구성 요소 트레이(폼 아래쪽 테두리 아래의 작은 영역)에서 TableAdapter를 검사합니다.

    또는

  • TableAdapter를 만든 다음 프로젝트를 빌드합니다. TableAdapter가 도구 상자에 나타납니다. 도구 상자에서 폼으로 TableAdapter를 끌어 놓아 인스턴스를 만듭니다. 인스턴스의 이름을 보려면 구성 요소 트레이에서 TableAdapter를 검사합니다.

    또는

  • TableAdapter 인스턴스를 프로그래밍 방식으로 만듭니다.

    Dim CustomersTableAdapter1 As NorthwindDataSetTableAdapters.CustomersTableAdapter
    CustomersTableAdapter1 = New NorthwindDataSetTableAdapters.CustomersTableAdapter()
    
    NorthwindDataSetTableAdapters.CustomersTableAdapter customersTableAdapter1;
    customersTableAdapter1 = new NorthwindDataSetTableAdapters.CustomersTableAdapter();
    

기존 데이터 테이블을 채우는 TableAdapter 쿼리 실행(Fill() 메서드)

기존 데이터 테이블을 채우는 TableAdapter 쿼리를 실행하려면

  • TableAdapter의 Fill 또는 FillBy 쿼리를 호출하고 채울 데이터 테이블을 전달합니다. 예를 들어, 다음 코드에서는 Fill 쿼리를 실행하고 Customers 테이블을 채웁니다.

    CustomersTableAdapter1.Fill(NorthwindDataSet1.Customers)
    
    customersTableAdapter1.Fill(northwindDataSet1.Customers);
    

새 데이터 테이블을 반환하는 TableAdapter 쿼리 실행(GetData() 메서드)

새 데이터 테이블을 반환하는 TableAdapter 쿼리를 실행하려면

  • TableAdapter의 GetData 또는 GetDataBy 쿼리를 호출하여 해당 쿼리 결과로 채워진 형식화된 데이터 테이블을 반환합니다. 예를 들어, 다음 코드에서는 GetData 쿼리를 실행하고 Customers 테이블을 반환합니다.

    Dim newCustomersTable As NorthwindDataSet.CustomersDataTable
    newCustomersTable = CustomersTableAdapter1.GetData()
    
    NorthwindDataSet.CustomersDataTable newCustomersTable;
    newCustomersTable = customersTableAdapter1.GetData();
    

단일(스칼라) 값을 반환하는 TableAdapter 쿼리 실행

도구 상자에서 데이터 집합 디자이너로 쿼리를 바로 끌어 놓아 독립 실행형 쿼리(데이터 테이블이 없는 쿼리)를 만들 수 있습니다.

단일(스칼라) 값을 반환하는 TableAdapter 쿼리를 실행하려면

  • TableAdapter의 인스턴스를 만들고 반환 값을 보유할 변수를 선언한 다음 해당 인스턴스를 쿼리의 결과에 할당합니다. 다음 예제에서는 QueriesTableAdapter에 CustomerCount라는 이름의 쿼리가 있다고 가정합니다.

    Dim scalarQueriesTableAdapter As NorthwindDataSetTableAdapters.QueriesTableAdapter
    scalarQueriesTableAdapter = New NorthwindDataSetTableAdapters.QueriesTableAdapter()
    
    Dim returnValue As Integer
    returnValue = CType(scalarQueriesTableAdapter.CustomerCount(), Integer)
    
    NorthwindDataSetTableAdapters.QueriesTableAdapter scalarQueriesTableAdapter;
    scalarQueriesTableAdapter = new NorthwindDataSetTableAdapters.QueriesTableAdapter();
    
    int returnValue;
    returnValue = (int)scalarQueriesTableAdapter.CustomerCount();
    

참고 항목

작업

방법: TableAdapter 만들기

방법: TableAdapter 쿼리 만들기

방법: TableAdapter 쿼리 편집

방법: TableAdapter를 사용하여 데이터베이스에 직접 액세스

연습: TableAdapter DBDirect 메서드를 사용하여 데이터 저장

방법: Windows Forms BindingNavigator 컨트롤을 사용하여 데이터 탐색

연습: Windows Form에 데이터 표시

개념

TableAdapter 개요

Visual Studio에서 데이터에 Windows Forms 컨트롤 바인딩

데이터 집합 디자이너

데이터 소스 개요

기타 리소스

데이터를 응용 프로그램으로 페치

데이터 유효성 검사