次の方法で共有


AdoQueryConnection.Command プロパティ

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

名前空間: Microsoft.Office.InfoPath
アセンブリ: Microsoft.Office.InfoPath (microsoft.office.infopath.dll 内)

構文

'宣言
Public MustOverride Property Command As String
'使用
Dim instance As AdoQueryConnection
Dim value As String

value = instance.Command

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

プロパティ値

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

コメント

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

メモメモ :

ADOQueryConnection オブジェクトが動作するには、Microsoft SQL Server および Microsoft Access データベースが必要です。

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

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

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

最初に、my:EmpID フィールドにユーザーが入力した値を使用して、Command プロパティで SQL コマンド テキストを更新します。次に、Execute メソッドを使用して、データ接続によって取得されたデータを更新します。これにより、フォームの Employees テーブルにバインドされている [繰り返しテーブル] コントロールに表示されているレコードが更新されます。この例では、メイン データ ソースの 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 クラス
AdoQueryConnection のメンバ
Microsoft.Office.InfoPath 名前空間