IDbCommand.CommandText 屬性

定義

取得或設定要對資料來源執行的文字命令。

public:
 property System::String ^ CommandText { System::String ^ get(); void set(System::String ^ value); };
public string CommandText { get; set; }
member this.CommandText : string with get, set
Public Property CommandText As String

屬性值

要執行的文字命令。 預設值為空字串 ("")。

範例

下列範例會建立衍生類別的實例, OleDbCommand 並設定其部分屬性。

public void CreateOleDbCommand()
{
   OleDbCommand command = new OleDbCommand();
   command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID;";
   command.CommandType = CommandType.Text;
}
Public Sub CreateOleDbCommand()
    Dim command As New OleDbCommand()
    command.CommandText = "SELECT * FROM Categories ORDER BY CategoryID;"
    command.CommandType = CommandType.Text
End Sub

備註

CommandType當 屬性設定為 StoredProcedure 時,請將 CommandText 屬性設定為預存程式的名稱。 如果預存程式名稱包含任何特殊字元,使用者可能需要使用逸出字元語法。 當您呼叫其中一個 Execute 方法時,此命令會呼叫這個預存程式。

適用於

另請參閱