DataSource.QueryConnection property

Office 2013 and later

Gets a reference to the DataConnection object associated with the data source.

Namespace:  Microsoft.Office.InfoPath
Assembly:  Microsoft.Office.InfoPath (in Microsoft.Office.InfoPath.dll)

public abstract DataConnection QueryConnection { get; }

Property value

Type: Microsoft.Office.InfoPath.DataConnection
A DataConnection associated with the data source.

After you have set a reference to the DataConnection object that the QueryConnection property returns, you can use the properties and methods that the particular DataConnection object provides.

This member can be accessed only by forms running in the same domain as the currently open form, or by forms that have been granted cross-domain permissions.

This type or member can be accessed from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.

In the following example, the QueryConnection property of the DataSource object is used to return a reference to the data connection that is associated with the DataSource object, which in this example is an ADOQueryConnection object. The code then uses the Command() property of the ADOQueryConnection class to display the SQL command text in a message box.

AdoQueryConnection myConnection = 
MessageBox.Show("SQL command text: " + myConnection.Command);