Compartilhar via


AdoQueryConnection.Command Propriedade

Definição

Obtém ou define o texto da cadeia de caracteres de comando SQL para um AdoQueryConnection objeto.

public:
 abstract property System::String ^ Command { System::String ^ get(); void set(System::String ^ value); };
public abstract string Command { get; set; }
member this.Command : string with get, set
Public MustOverride Property Command As String

Valor da propriedade

O texto do comando SQL da conexão de dados.

Exemplos

No exemplo a seguir, a propriedade Command da classe ADOQueryConnection e o Execute() método da DataConnection classe são usados para consultar uma tabela em uma fonte de dados secundária chamada Employees. A consulta é executada na conexão de dados criada no modo de design do InfoPath para o banco de dados que contém a tabela Funcionários , que também é chamada de "Funcionários".

Primeiro, o valor inserido pelo usuário no campo my:EmpID é usado para atualizar o texto do comando SQL usando a propriedade Command . Em seguida, o método Execute é usado para atualizar os dados recuperados pela conexão de dados, que atualiza o registro exibido em um controle Tabela Repetida que está vinculado à tabela Funcionários no formulário. Este exemplo requer o campo my:EmpID no main fonte de dados vinculada a um controle Text Box em uma exibição que contém um controle Button para invocar o código a seguir.

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

Comentários

A propriedade Command do objeto ADOQueryConnection contém o texto de comando SQL usado pela conexão de dados ADO para recuperar dados de uma fonte de dados externa do ActiveX Data Objects/OLEDB.

Observação: o objeto ADOQueryConnection é limitado a funcionar apenas com bancos de dados microsoft SQL Server e Microsoft Access.

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.

Aplica-se a