次の方法で共有


AdoSubmitConnection.Connection プロパティ

AdoSubmitConnection オブジェクトに使用される接続文字列を取得または設定します。

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

構文

'宣言
Public MustOverride Property Connection As String
    Get
    Set
'使用
Dim instance As AdoSubmitConnection
Dim value As String

value = instance.Connection

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

プロパティ値

型: System.String
データ接続の接続文字列。

解説

ADOSubmitConnection オブジェクトの Connection プロパティは、ActiveX Data Objects/OLEDB 外部データ ソースに接続するために ADO データ接続によって使用される接続文字列へのアクセスを提供します。

重要

ADOSubmitConnection オブジェクトが存在できるのは、対応する ADOQueryConnection オブジェクトがあり、両方のオブジェクトで表されるデータ接続で、同じプロパティ値のセットを共有している場合のみです。ADOSubmitConnection オブジェクトのこのプロパティの値を変更すると、対応する ADOQueryConnection オブジェクトの同じプロパティの値も変更されます。

注意

ADOSubmitConnection オブジェクトが機能するのは、Microsoft SQL Server および Microsoft Access データベースのみに限定されています。

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

この型またはメンバーには、Microsoft InfoPath Filler で開かれたフォームを実行中のコードからのみアクセスできます。

次の例では、[ボタン] コントロールのイベント ハンドラーは AdoSubmitConnection クラスの Connection プロパティを使用して、Employees という名前のセカンダリ データ ソースの接続文字列を更新し、メイン データ ソースの ServerName フィールドに入力した値を使用して新しいサーバーを示します。次に、DataConnection クラスの Execute メソッドを使用して、新しいサーバーのデータ接続が再クエリされます。

public void ChangeServerName_Clicked(object sender, ClickedEventArgs e)
{
   // Get the Employees connection from the 
   //DataConnections collection.
   AdoSubmitConnection myAdoSubmitConnection = 
      (AdoSubmitConnection)(this.DataConnections["Employees"]);
   
   // Get the new server name from the ServerName field in 
   // the main data source.
   XPathNavigator myNav = 
      CreateNavigator().SelectSingleNode("/my:myFields/my:ServerName",
      NamespaceManager);
   string newServer = myNav.InnerXml;

   // Build the new connection string.
   string connectionString = 
      "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;";
   connectionString += "Initial Catalog=SalesDB;Data Source=" + 
      newServer;

   // Set the new connection string.
   myAdoSubmitConnection.Connection = connectionString;

   // Requery the data source.
   myAdoSubmitConnection.Execute();
}
Public Sub ChangeServerName_Clicked(ByVal sender As Object, _
   ByVal e As ClickedEventArgs)
   ' Get the Employees connection from 
   ' the DataConnections collection.
   Dim myAdoSubmitConnection As AdoSubmitConnection = _
      DirectCast(Me.DataConnections("Employees"), AdoSubmitConnection)

   ' Get the new server name from the ServerName field in 
   ' the main data source.
   Dim myNav As XPathNavigator = _
     CreateNavigator().SelectSingleNode("/my:myFields/my:ServerName", _
      NamespaceManager)
   Dim newServer As String = myNav.InnerXml

   ' Build the new connection string.
   Dim connectionString As String = _
      "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;"
   connectionString = connectionString & _
      "Initial Catalog=SalesDB;Data Source=" & newServer

   ' Requery the data source.
    myAdoSubmitConnection.Execute()
End Sub

関連項目

参照

AdoSubmitConnection クラス

AdoSubmitConnection メンバー

Microsoft.Office.InfoPath 名前空間