Share via


AdoQueryConnection.Command 속성

AdoQueryConnection 개체에 대한 SQL 명령 문자열 텍스트를 가져오거나 설정합니다.

네임스페이스:  Microsoft.Office.InfoPath
어셈블리:  Microsoft.Office.InfoPath(Microsoft.Office.InfoPath.dll)

구문

‘선언
Public MustOverride Property Command As String
    Get
    Set
‘사용 방법
Dim instance As AdoQueryConnection
Dim value As String

value = instance.Command

instance.Command = value
public abstract string Command { get; set; }

속성 값

형식: System.String
데이터 연결의 SQL 명령 텍스트입니다.

주의

ADOQueryConnection 개체의 Command 속성은 ActiveX Data Objects/OLEDB 외부 데이터 원본으로부터 데이터를 가져오기 위해 ADO 데이터 연결에서 사용하는 SQL 명령 텍스트를 포함합니다.

참고 사항참고 사항

ADOQueryConnection 개체는 Microsoft SQL Server 및 Microsoft Access 데이터베이스에서만 사용할 수 있도록 제한됩니다.

이 멤버는 현재 열려 있는 양식과 같은 도메인에서 실행하는 양식 또는 도메인 간 권한이 부여된 양식에서만 액세스할 수 있습니다.

이 형식 또는 멤버는 Microsoft InfoPath Filer 또는 웹 브라우저에서 연 양식에서 실행되는 코드에서 액세스할 수 있습니다.

다음 예제에서는 ADOQueryConnection 클래스의 Command 속성 및 DataConnection 클래스의 Execute 메서드를 사용하여 보조 데이터 원본에 있는 Employees라고 하는 테이블을 쿼리합니다. 이 쿼리는 InfoPath 디자인 모드에서 Employees 테이블을 포함하는 데이터베이스에 설정된 데이터 연결에 대해 수행되며 이 쿼리의 이름도 "Employees"로 지정됩니다.

먼저 사용자가 my:EmpID 필드에 입력한 값을 사용하여 Command 명령을 통해 SQL 명령 텍스트를 업데이트합니다. 그런 다음 Execute 메서드를 사용하여 데이터 연결에서 검색한 데이터를 새로 고칩니다. 이렇게 하면 양식의 Employees 테이블에 바인딩된 반복 표 컨트롤에 표시되는 레코드가 업데이트됩니다. 이 예제에서는 다음 코드를 호출하기 위해 기본 데이터 원본의 my:EmpID 필드가 보기에서 Button 컨트롤을 포함하는 텍스트 상자 컨트롤에 바인딩되어 있어야 합니다.

public void RefreshData_Clicked(object sender, ClickedEventArgs e)
{
   // Get the Employees connection from the 
   // DataConnections collection.
   AdoQueryConnection myAdoQueryConnection =
      (AdoQueryConnection)(this.DataConnections["Employees"]);

   // Get the employee's ID from the EmpID field in 
   // the main data source.
   XPathNavigator myNav = 
      CreateNavigator().SelectSingleNode("/my:myFields/my:EmpID", 
      NamespaceManager);
   // Assign the value from the field to a variable.
   string employeeID = myNav.InnerXml;

   // Change the SQL command for Employees connection to retrieve 
   // the record of the Employee's ID entered by the user.
   myAdoQueryConnection.Command = 
      "select * from [Employees] where [EmployeeID] = " + employeeID;

   // Execute the updated command against the data connection to 
   // refresh the data.
   myAdoQueryConnection.Execute();
}
Public Sub RefreshData_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
   ' Get the Employees connection from the 
   ' DataConnections collection.
   Dim myAdoQueryConnection As AdoQueryConnection = _
      DirectCast(Me.DataConnections("Employees"), AdoQueryConnection)

   ' Get the employee's ID from the EmpID field in 
   ' the main data source.
   Dim myNav As XPathNavigator = _
      CreateNavigator().SelectSingleNode("/my:myFields/my:EmpID", _
      NamespaceManager)
   Dim employeeID As String = myNav.InnerXml

   ' Change the SQL command for Employees connection to retrieve 
   ' the record of the Employee's ID entered by the user.
   myAdoQueryConnection.Command = _
      "select * from [Employees] where [EmployeeID] = " + employeeID

   ' Execute the updated command against the data connection to 
   ' refresh the data.
    myAdoQueryConnection.Execute()
End Sub

참고 항목

참조

AdoQueryConnection 클래스

AdoQueryConnection 멤버

Microsoft.Office.InfoPath 네임스페이스