Edit

Share via


DataConnection.Execute Method

Definition

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.

public:
 abstract void Execute();
public abstract void Execute ();
abstract member Execute : unit -> unit
Public MustOverride Sub Execute ()

Exceptions

The execute operation failed.

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

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

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

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.

Examples

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();
}
Public Sub RefreshData_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 employee's ID from the EmpID field in 
   ' the main data source.
   Dim myNav As XPathNavigator = _
      CreateNavigator().SelectSingleNode("/my:myFields/my:EmpID", _
      NamespaceManager)
   Dim employeeID As String = 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()
End Sub

Remarks

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.

AdoQueryConnection Query
AdoSubmitConnection Submit
BdcQueryConnection Query
BdcSubmitConnection Submit
EmailSubmitConnection Submit
FileQueryConnection Query
FileSubmitConnection Submit
SharePointListRWQueryConnectionNoteThe 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.

Applies to