Export (0) Print
Expand All

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)

public abstract void Execute()

ExceptionCondition
WebException

The execute operation failed.

ArgumentNullException

The parameters passed to this method are a null reference (Nothing in Visual Basic).

ArgumentException

The parameters passed to this method are not valid. For example, they are of the wrong type or format.

InvalidOperationException

For submit operations, the Execute() method was called from an event handler for the Loading event.

SEHException

A structured exception handler (SEH) error was thrown from unmanaged code that is not mapped to an equivalent managed code exception. For more information, search on "unmanaged exceptions" and "Structured Exception Handling" in the MSDN Library.

When designing a form template, you can use the Submit Actions commands on the Data tab 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 Data tab to define settings for submitting or receiving data, which are 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.

Class

Operation

AdoQueryConnection

Query

AdoSubmitConnection

Submit

BdcQueryConnection

Query

BdcSubmitConnection

Submit

EmailSubmitConnection

Submit

FileQueryConnection

Query

FileSubmitConnection

Submit

SharePointListRWQueryConnection

NoteNote

The SharepointListQueryConnection class used in previous versions of InfoPath has been deprecated.

Query

WebServiceConnection

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 InfoPath Filler 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 =
      (AdoQueryConnection)(this.DataConnections["Employees"]);

   // Get the employee's ID from the EmpID field in 
   // the main data source.
   XPathNavigator myNav = 
      CreateNavigator().SelectSingleNode("/my:myFields/my:EmpID", 
      NamespaceManager);
   // 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.
   myAdoQueryConnection.Execute();
}
Show:
© 2014 Microsoft