SqlCommand.CommandType Proprietà

Definizione

Ottiene o imposta un valore che indica come interpretare la proprietà CommandText.

public:
 virtual property System::Data::CommandType CommandType { System::Data::CommandType get(); void set(System::Data::CommandType value); };
public:
 property System::Data::CommandType CommandType { System::Data::CommandType get(); void set(System::Data::CommandType value); };
public override System.Data.CommandType CommandType { get; set; }
[System.Data.DataSysDescription("DbCommand_CommandType")]
public System.Data.CommandType CommandType { get; set; }
member this.CommandType : System.Data.CommandType with get, set
[<System.Data.DataSysDescription("DbCommand_CommandType")>]
member this.CommandType : System.Data.CommandType with get, set
Public Overrides Property CommandType As CommandType
Public Property CommandType As CommandType

Valore della proprietà

Uno dei valori di CommandType. Il valore predefinito è Text.

Implementazioni

Attributi

Eccezioni

Il valore non era un valore CommandType valido.

Esempio

Nell'esempio seguente viene creato un oggetto SqlCommand e vengono impostate alcune delle relative proprietà.

public void CreateSqlCommand()
{
   SqlCommand command = new SqlCommand();
   command.CommandTimeout = 15;
   command.CommandType = CommandType.Text;
}
Public Sub CreateSqlCommand()
    Dim command As New SqlCommand()
    command.CommandTimeout = 15
    command.CommandType = CommandType.Text
End Sub

Commenti

Quando si imposta la CommandType proprietà StoredProceduresu , è necessario impostare la CommandText proprietà sul nome della stored procedure. Il comando eseguirà la stored procedure quando si chiama uno dei metodi Execute.

Il provider di dati Microsoft .NET Framework per SQL Server non supporta il segnaposto punto interrogativo (?) per il passaggio di parametri a un'istruzione SQL o a una stored procedure chiamata con un CommandType oggetto .Text In questo caso, è necessario usare i parametri denominati. Ad esempio:

SELECT * FROM Customers WHERE CustomerID = @CustomerID

Per altre informazioni, vedere Configurazione dei parametri e dei tipi di dati dei parametri.

Si applica a

Vedi anche