Language

AdoQueryConnection.Connection プロパティ

定義

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

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

プロパティ値

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

例

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

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

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

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

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

適用対象