Command property
Collapse the table of content
Expand the table of content

AdoQueryConnection.Command property

Office 2013 and later

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

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

public abstract string Command { get; set; }

Property value

Type: System.String
The SQL command text of the data connection.

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

NoteNote

The ADOQueryConnection 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 from code running in forms opened in Microsoft InfoPath Filler or in a Web browser.

In the following example, the Command property of the ADOQueryConnection 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 also named "Employees."

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 that is 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.
   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:
© 2016 Microsoft