Proprietà AdoQueryConnection.Command

Ottiene o imposta il testo della stringa di comando SQL per un oggetto AdoQueryConnection.

Spazio dei nomi: Microsoft.Office.InfoPath
Assembly: Microsoft.Office.InfoPath (in microsoft.office.infopath.dll)

Sintassi

Public MustOverride Property Command As String

Dim instance As AdoQueryConnection
Dim value As String

value = instance.Command

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

Valore proprietà

Testo del comando SQL per la connessione dati.

Osservazioni

La proprietà Command dell'oggetto ADOQueryConnection contiene il testo del comando SQL utilizzato dalla connessione dati ADO per recuperare i dati da un'origine dati esterna ADO (ActiveX Data Objects)/OLEDB.

Nota:

L'oggetto ADOQueryConnection può essere utilizzato solo con i database di Microsoft SQL Server e di Microsoft Access.

Possono accedere a questo membro solo moduli eseguiti nello stesso dominio del modulo aperto oppure moduli a cui sono state concesse autorizzazioni tra domini.

A questo tipo o membro può accedere solo il codice in esecuzione in moduli aperti in Microsoft Office InfoPath 2007 o in un browser.

Esempio

Nell'esempio seguente vengono utilizzati la proprietà Command della classe ADOQueryConnection e il metodo Execute della classe DataConnection per eseguire una query in una tabella in un'origine dati secondaria denominata Employees. La query viene eseguita nella connessione dati creata in modalità progettazione di InfoPath al database che contiene la tabella Employees, denominato anch'esso "Employees".

Innanzitutto, il valore immesso dall'utente nel campo my:EmpID viene utilizzato per aggiornare il testo del comando SQL tramite la proprietà Command. Viene quindi utilizzato il metodo Execute per aggiornare i dati recuperati dalla connessione dati. In questo modo viene aggiornato il record visualizzato in un controllo Tabella ripetuta associato alla tabella Employees del modulo. L'esempio richiede il campo my:EmpID nell'origine dati principale associato a un controllo Casella di testo in una visualizzazione che include un controllo Button per richiamare il codice seguente.

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

Vedere anche

Riferimenti

Classe AdoQueryConnection
Membri AdoQueryConnection
Spazio dei nomi Microsoft.Office.InfoPath