次の方法で共有


AdoQueryConnection.Connection プロパティ

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

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

構文

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

value = instance.Connection

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

プロパティ値

AdoQueryConnection オブジェクトによって表されるデータ接続に対する接続文字列。

コメント

ADOQueryConnection クラスの Connection プロパティは、ActiveX Data Objects/OLEDB 外部データ ソースに接続するために ADO データ接続が使用する接続文字列へのアクセスを提供します。

メモメモ :

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

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

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

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

public void ChangeServerName_Clicked(object sender, ClickedEventArgs e)
{
   // Get the Employees connection from the 
   //DataConnections collection.
   AdoQueryConnection myAdoQueryConnection = 
      (AdoQueryConnection)(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.
   myAdoQueryConnection.Connection = connectionString;

   // Requery the data source.
   myAdoQueryConnection.Execute();
}
Public Sub ChangeServerName_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 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.
    myAdoQueryConnection.Execute()
End Sub

関連項目

参照

AdoQueryConnection クラス
AdoQueryConnection のメンバ
Microsoft.Office.InfoPath 名前空間