MySQL Connector/Net |
MySqlCommand Constructor (String, MySqlConnection, MySqlTransaction) |
MySqlCommand Class Example See Also Send Feedback |
Initializes a new instance of the MySqlCommand class
with the text of the query, a MySqlConnection, and the
MySqlTransaction.
Namespace:
MySql.Data.MySqlClient
Assembly:
MySql.Data (in MySql.Data.dll) Version: 6.2.2.0
Syntax
C# |
---|
public MySqlCommand( string cmdText, MySqlConnection connection, MySqlTransaction transaction ) |
Visual Basic (Declaration) |
---|
Public Sub New ( _ cmdText As String, _ connection As MySqlConnection, _ transaction As MySqlTransaction _ ) |
Visual C++ |
---|
public: MySqlCommand( String^ cmdText, MySqlConnection^ connection, MySqlTransaction^ transaction ) |
Parameters
- cmdText
- Type: System..::.String
The text of the query.
- connection
- Type: MySql.Data.MySqlClient..::.MySqlConnection
A MySqlConnection that represents the connection to an instance of SQL Server.
- transaction
- Type: MySql.Data.MySqlClient..::.MySqlTransaction
The MySqlTransaction in which the MySqlCommand executes.
Remarks
When an instance of MySqlCommand is created,
the following read/write properties are set to initial values.
Properties | Initial Value |
---|---|
CommandText | cmdText |
CommandTimeout | 0 |
CommandType | CommandType.Text |
Connection | connection |
You can change the value for any of these properties through a separate call to the property.
Examples
The following example creates a MySqlCommand and
sets some of its properties.
CopyVB.NET
Public Sub CreateMySqlCommand() Dim conn as new MySqlConnection("server=myServer") conn.Open(); Dim txn as MySqlTransaction = conn.BeginTransaction() Dim sql as String = "SELECT * FROM mytable" Dim myCommand As New MySqlCommand(sql, conn, txn) myCommand.CommandType = CommandType.Text End Sub
CopyC#
public void CreateMySqlCommand() { MySqlConnection conn = new MySqlConnection("server=myserver") conn.Open(); MySqlTransaction txn = conn.BeginTransaction(); string sql = "SELECT * FROM mytable"; MySqlCommand myCommand = new MySqlCommand(sql, conn, txn); myCommand.CommandType = CommandType.Text; }