This documentation is archived and is not being maintained.

IDbCommand.CommandText Property

Gets or sets the text command to run against the data source.

[Visual Basic]
Property CommandText As String
string CommandText {get; set;}
__property String* get_CommandText();
__property void set_CommandText(String*);
function get CommandText() : String;function set CommandText(String);

Property Value

The text command to execute. The default value is an empty string ("").


When the CommandType property is set to StoredProcedure, set the CommandText property to the name of the stored procedure. The user may be required to use escape character syntax if the stored procedure name contains any special characters. The command will call this stored procedure when you call one of the Execute methods.


[Visual Basic, C#, C++] The following example creates an instance of a derived class, OleDbCommand and sets some of its properties.

[Visual Basic] 
Public Sub CreateMyOleDbCommand()
    Dim myCommand As New OleDbCommand()
    myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID"
    myCommand.CommandType = CommandType.Text
End Sub

public void CreateMyOleDbCommand() 
   OleDbCommand myCommand = new OleDbCommand();
   myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
   myCommand.CommandType = CommandType.Text;

 void CreateMyOleDbCommand() 
    OleDbCommand* myCommand = new OleDbCommand();
    myCommand->CommandText = S"SELECT * FROM Categories ORDER BY CategoryID";
    myCommand->CommandType = CommandType::Text;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework

See Also

IDbCommand Interface | IDbCommand Members | System.Data Namespace | CommandType | UpdatedRowSource