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)
Syntax
'Declaration
Public MustOverride Sub Execute
'Usage
Dim instance As DataConnection
instance.Execute()
public abstract void Execute()
Exceptions
Exception | Condition |
---|---|
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. |
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.
Class |
Operation |
---|---|
Query |
|
Submit |
|
Query |
|
Submit |
|
Submit |
|
Query |
|
Submit |
|
SharePointListRWQueryConnection Note The SharepointListQueryConnection class used in previous versions of InfoPath has been deprecated. |
Query |
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.
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