Share via


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 override System.Data.CommandType CommandType { get; set; }
member this.CommandType : System.Data.CommandType with get, set
Public Overrides Property CommandType As CommandType

Valore della proprietà

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

Esempio

L'esempio seguente crea un oggetto SqlCommand e imposta alcune delle relative proprietà.

// <Snippet1>
using System;
using System.Xml;
using System.Data;
using Microsoft.Data.SqlClient;
using System.Data.Common;
using System.Windows.Forms;

public class Form1 : Form
{
    protected DataSet DataSet1;
    protected DataGrid dataGrid1;


    public void CreateSqlCommand()
    {
        SqlCommand command = new SqlCommand();
        command.CommandTimeout = 15;
        command.CommandType = CommandType.Text;
    }
    // </Snippet1>
}

Commenti

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

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

SELECT * FROM Customers WHERE CustomerID = @CustomerID

Per altre informazioni, vedere Configurazione dei parametri.

Si applica a