We recommend using Visual Studio 2017

DataConnection.Execute Method

Depending on which ConnectionTypeConnection class it is called from, executes a submit or query operation on the data connection using the declaratively defined values for the submitted data, query parameters, or data to retrieve.

Namespace: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

Exception typeCondition


The execute operation failed.

When designing a form template, you can use the Form Submit Options command on the Tools menu to define the destination to submit to and related settings that are stored in the form template file's solution definition file (.xsf). You can also use the Data Connections command on the Tools menu to define settings for submitting or receiving data, which are also stored in the solution definition file (.xsf). Using the Execute method performs a submit or query operation on the data connection using these declaratively defined settings.

The DataConnection.Execute method is inherited by all classes that represent data connections, and is exposed as an inherited method of that class, such as the EmailSubmitConnection.Execute() method. Depending on the kind of data connection the inheriting class represents, the Execute method will perform the declared submit or query operation appropriate to that connection.














Submit or Query

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 Office InfoPath 2007 or in a Web browser.

In the following example, after the Command property of the ADOQueryConnection class is used to update the SQL command text of the data connection, the Execute method of the DataConnection class is used to execute the query to refresh the data in the form.

public void RefreshData_Clicked(object sender, ClickedEventArgs e)
   // Get the Employees connection from the 
   // DataConnections collection.
   AdoQueryConnection myAdoQueryConnection =

   // Get the employee's ID from the EmpID field in 
   // the main data source.
   XPathNavigator myNav = 
   // Assign the value from the field to a variable.
   string employeeID = myNav.InnerXml;

   // Change the SQL command for Employees connection to retrieve 
   // the record of the Employee's ID entered by the user.
   myAdoQueryConnection.Command = 
      "select * from [Employees] where [EmployeeID] = " + employeeID;

   // Execute the updated command against the data connection to 
   // refresh the data.

Community Additions