SqlCommand.CommandType Proprietà
Definizione
Importante
Alcune informazioni sono relative alla release non definitiva del prodotto, che potrebbe subire modifiche significative prima della release definitiva. Microsoft non riconosce alcuna garanzia, espressa o implicita, in merito alle informazioni qui fornite.
Ottiene o imposta un valore che indica come deve essere interpretata la CommandText proprietà.
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 CommandType valori. Il valore predefinito è Text.
Implementazioni
- Attributi
Eccezioni
Il valore non è valido CommandType.
Esempio
Nell'esempio seguente viene creato un SqlCommand oggetto 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à su StoredProcedure, è necessario impostare la CommandText proprietà sul nome della stored procedure. Il comando esegue questa 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 .CommandTypeText In questo caso, i parametri denominati devono essere usati. Per esempio:
SELECT * FROM Customers WHERE CustomerID = @CustomerID
Per altre informazioni, vedere Configuring Parameters and Parameter Data Types.