Language

AdoQueryConnection.Command プロパティ

定義

オブジェクトの SQL コマンド文字列テキストを AdoQueryConnection 取得または設定します。

public:
 abstract property System::String ^ Command { System::String ^ get(); void set(System::String ^ value); };
public abstract string Command { get; set; }
member this.Command : string with get, set
Public MustOverride Property Command As String

プロパティ値

データ接続の SQL コマンド テキスト。

例

次の例では、ADOQueryConnection クラスの Command プロパティと クラスのメソッドをExecute()DataConnection使用して、Employees という名前のセカンダリ データ ソース内のテーブルのクエリを実行します。 クエリは、Employees テーブルを含むやはり Employees という名前のデータベースに対する、InfoPath デザイン モードで作成されたデータ接続に対して実行されます。

まず、ユーザーがフィールド my:EmpID に入力した値を使用して、 Command プロパティを使用して SQL コマンド テキストを更新します。 次に、 Execute メソッドを使用して、データ接続によって取得されたデータを更新します。これにより、フォームの Employees テーブルにバインドされている繰り返しテーブル コントロールに表示されるレコードが更新されます。 この例では、次のコードを呼び出すために、Button コントロールを含むビューの Text Box コントロールにバインドされたメイン データ ソースの my:EmpID フィールドが必要です。

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 オブジェクトの Command プロパティには、ActiveX Data Objects/OLEDB 外部データ ソースからデータを取得するために ADO データ接続が使用する SQL コマンド テキストが含まれます。

注: ADOQueryConnection オブジェクトは、Microsoft SQL Server および Microsoft Access データベースでのみ動作するように制限されています。

このメンバは、現在開いているフォームと同じドメインで実行中のフォーム、またはクロスドメインのアクセス許可が与えられたフォームだけがアクセスできます。

この型またはメンバーには、Microsoft InfoPath Filler または Web ブラウザーで開いたフォームで実行されるコードからアクセスできます。

適用対象