AdoQueryConnection.Command Property (Microsoft.Office.InfoPath)
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)
Syntax
'Declaration
Public MustOverride Property Command As String
'Usage
Dim instance As AdoQueryConnection
Dim value As String
value = instance.Command
instance.Command = value
public abstract string Command { get; set; }
Property Value
The SQL command text of the data connection.
Remarks
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.
Note
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 Office InfoPath 2007 or in a Web browser.
Example
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();
}
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
See Also
Reference
AdoQueryConnection Class
AdoQueryConnection Members
Microsoft.Office.InfoPath Namespace