次の方法で共有


AdoSubmitConnection.Command Property

Gets or sets the SQL command string text for an AdoSubmitConnection object.

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

Syntax

'Declaration
Public MustOverride Property Command As String
    Get
    Set
'Usage
Dim instance As AdoSubmitConnection
Dim value As String

value = instance.Command

instance.Command = value
public abstract string Command { get; set; }

Property Value

Type: System.String
The SQL command string for the data connection.

Remarks

The Command property of the ADOSubmitConnection object contains the SQL command text that is used by the ADO data connection to submit data to an ActiveX Data Objects/OLEDB external data source.

Important

An ADOSubmitConnection object can only exist when there is a corresponding ADOQueryConnection object, and the data connections represented by both objects share the same set of property values. Changing the value of this property for the ADOSubmitConnection object will also change the value of the same property for the corresponding ADOQueryConnection object.

Note

The ADOSubmitConnection object is limited to work only with Microsoft SQL Server and Microsoft Access databases.

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 only from code running in forms opened in Microsoft InfoPath Filler.

Examples

In the following example, the Command property of the AdoSubmitConnection class and the Execute method of the DataConnection class are used to query a table in a secondary data source named Employees. The query is executed against the data connection created in InfoPath design mode to the database that contains the Employees table, which is named "EmployeesSubmit".

First, the value entered by the user in the field my:EmpID is used to update the SQL command text using the Command property. Then, the Execute method is used to refresh the data retrieved by data connection, which updates the record displayed in a Repeating Table control which bound to the Employees table on the form. This example requires the my:EmpID field in the main data source bound to a Text Box control in a view that contains a Button control to invoke the following code.

public void RefreshData_Clicked(object sender, ClickedEventArgs e)
{
   // Get the Employees connection from the 
   // DataConnections collection.
   AdoSubmitConnection myAdoSubmitConnection =
      (AdoSubmitConnection)(this.DataConnections["EmployeesSubmit"]);

   // 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.
   myAdoSubmitConnection.Command = 
      "select * from [Employees] where [EmployeeID] = " + employeeID;

   // Execute the updated command against the data connection to 
   // refresh the data.
   myAdoSubmitConnection.Execute();
}
Public Sub RefreshData_Clicked(ByVal sender As Object, ByVal e As ClickedEventArgs)
   ' Get the Employees connection from the 
   ' DataConnections collection.
   Dim myAdoSubmitConnection As AdoSubmitConnection = _
      DirectCast(Me.DataConnections("EmployeesSubmit"), _
      AdoSubmitConnection)

   ' 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.
    myAdoSubmitConnection.Execute()
End Sub

See Also

Reference

AdoSubmitConnection Class

AdoSubmitConnection Members

Microsoft.Office.InfoPath Namespace