SqlCommand.CommandType 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得或設定一個值,指示該 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
屬性值
這是其中一項 CommandType 價值。 預設值為 Text。
實作
- 屬性
例外狀況
該值並非有效 CommandType。
範例
以下範例會建立 並 SqlCommand 設定其部分性質。
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
備註
當你將屬性設 CommandType 為 StoredProcedure時,應該將該屬性設 CommandText 為儲存程序的名稱。 當你呼叫其中一個 Execute 方法時,指令會執行這個儲存程序。
Microsoft .NET Framework 資料提供者 for SQL Server 不支援用來傳入參數給 SQL 陳述句或以 CommandType 為 的 Text儲存程序的參數的問號(?)佔位符。 此時必須使用命名參數。 例如:
選擇 * 從客戶中 其中 CustomerID = @CustomerID
欲了解更多資訊,請參閱 「參數與參數資料型態的配置」。