CommandText Property

MySQL Connector.Net

Collapse image Expand Image Copy image CopyHover image
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.8.4.0

Syntax

C#
public override string CommandText { get; set; }
Visual Basic
Public Overrides Property CommandText As String
	Get
	Set
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.
Visual Basic Copy imageCopy
Public Sub CreateMySqlCommand()
Dim myCommand As New MySqlCommand()
myCommand.CommandText = "SELECT * FROM Mytable ORDER BY id"
myCommand.CommandType = CommandType.Text
End Sub
C# Copy imageCopy
public void CreateMySqlCommand()
{
MySqlCommand myCommand = new MySqlCommand();
myCommand.CommandText = "SELECT * FROM mytable ORDER BY id";
myCommand.CommandType = CommandType.Text;
}

See Also