CommandText Property

MySQL Connector/Net

Gets or sets the SQL statement to execute at the data source.

Namespace:  MySql.Data.MySqlClient
Assembly:  MySql.Data (in MySql.Data.dll) Version: 6.2.2.0

Syntax

C#
public override string CommandText { get; set; }
Visual Basic (Declaration)
Public Overrides Property CommandText As String
Visual C++
public:
virtual property String^ CommandText {
	String^ get () override;
	void set (String^ value) override;
}

Field Value

The SQL statement or stored procedure to execute. The default is an empty string.

Implements

IDbCommand..::.CommandText

Remarks

When the CommandType property is set to StoredProcedure, the CommandText property should be set 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 executes this stored procedure when you call one of the Execute methods. Starting with Connector/Net 5.0, having both a stored function and stored procedure with the same name in the same database is not supported. It is suggested that you provide unqiue names for your stored routines.

Examples

The following example creates a MySqlCommand and sets some of its properties.
CopyVB.NET
Public Sub CreateMySqlCommand()
Dim myCommand As New MySqlCommand()
myCommand.CommandText = "SELECT * FROM Mytable ORDER BY id"
myCommand.CommandType = CommandType.Text
End Sub
CopyC#
public void CreateMySqlCommand()
{
MySqlCommand myCommand = new MySqlCommand();
myCommand.CommandText = "SELECT * FROM mytable ORDER BY id";
myCommand.CommandType = CommandType.Text;
}

See Also