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
[C#]
string CommandText {get; set;}
[C++]
__property String* get_CommandText();
__property void set_CommandText(String*);
[JScript]
function get CommandText() : String;function set CommandText(String);

Property Value

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

Remarks

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.

Example

[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

[C#] 
public void CreateMyOleDbCommand() 
{
   OleDbCommand myCommand = new OleDbCommand();
   myCommand.CommandText = "SELECT * FROM Categories ORDER BY CategoryID";
   myCommand.CommandType = CommandType.Text;
}

[C++] 
public:
 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.

Requirements

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

Show: