XmlForm.QueryDataConnection property

Office 2013 and later

Gets a reference to the DataConnection object that represents the data connection that is associated with the form.

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

public abstract DataConnection QueryDataConnection { get; }

Property value

Type: Microsoft.Office.InfoPath.DataConnection
A DataConnection that represents the data connection that is associated with the form.

DataConnection objects provide properties and methods that retrieve and submit data to external data sources; the data connection that is associated with a form is dependent on the type of data source that was used when the form was initially created.

The QueryDataConnection property allows you to access an InfoPath form's primary data source. To access the data adapter objects used for a form's secondary data sources, use the DataSources property.

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 code example, the QueryDataConnection property of the XmlForm class is used to set a reference to the ADOQueryConnection and ADOSubmitConnection objects associated with the form template. Then the Command property of the ADOQueryConnection object and the Command property of the ADOQueryConnection objects are used to display the SQL command text for each connection type in a message box

ADOQueryConnection queryConnection;
ADOSubmitConnection submitConnection;

queryConnection = (ADOQueryConnection) this.QueryConnection;
MessageBox.Show("Query SQL command text: " + queryConnection.Command);

submitConnection = (ADOSubmitConnection) this.QueryConnection;
MessageBox.Show("Submit SQL command text: " + querySubmit.Command);
Show: