Share via


de la propiedad AdoQueryConnection.Command

Obtiene o establece el texto de cadena de comando SQL de un objeto AdoQueryConnection.

Espacio de nombres:  Microsoft.Office.InfoPath
Ensamblado:  Microsoft.Office.InfoPath (en Microsoft.Office.InfoPath.dll)

Sintaxis

'Declaración
Public MustOverride Property Command As String
    Get
    Set
'Uso
Dim instance As AdoQueryConnection
Dim value As String

value = instance.Command

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

Valor de propiedad

Tipo: System.String
Texto de comando SQL de la conexión de datos.

Comentarios

La propiedad Command del objeto ADOQueryConnection contiene el texto del comando SQL utilizado por la conexión de datos ADO para recuperar datos de un origen de datos ActiveX Data Objects/OLEDB externo.

Nota

El objeto ADOQueryConnection únicamente funciona con bases de datos de Microsoft SQL Server y Microsoft Access.

Únicamente se puede acceder a este miembro con formularios que se ejecuten en el mismo dominio que el formulario que está actualmente abierto o con formularios a los que se hayan concedido permisos entre dominios.

Se puede acceder a este tipo o miembro desde el código que se ejecuta en los formularios abiertos en Microsoft InfoPath Filler o en un explorador web.

Ejemplos

En el siguiente ejemplo, la propiedad Command de la clase ADOQueryConnection y el método Execute de la clase DataConnection se usan para hacer una consulta en una tabla en un origen de datos secundario denominado Employees. La consulta se ejecuta en la conexión de datos creada en el modo de diseño de InfoPath en la base de datos que contiene la tabla Employees, que también se llama "Employees".

Primero se usa el valor escrito por el usuario en el campo my:EmpID para actualizar el texto de comando SQL mediante la propiedad Command. A continuación, se usa el método Execute para actualizar los datos recuperados por la conexión de datos, que actualiza el registro mostrado en un control de Tabla extensible enlazado a la tabla Employees del formulario. En este ejemplo es necesario el campo my:EmpID del origen de datos principal enlazado a un control Cuadro de texto en una vista con un control Button para llamar al siguiente código.

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

Vea también

Referencia

clase AdoQueryConnection

Miembros AdoQueryConnection

Espacio de nombres Microsoft.Office.InfoPath