MySqlCommand Constructor

MySQL Connector.Net

Collapse image Expand Image Copy image CopyHover image
Initializes a new instance of the MySqlCommand class.

Overload List

  Name Description
Public method MySqlCommand()()()()
Initializes a new instance of the MySqlCommand class.
Public method MySqlCommand(String)
Initializes a new instance of the MySqlCommand class with the text of the query.
Public method MySqlCommand(String, MySqlConnection)
Initializes a new instance of the MySqlCommand class with the text of the query and a MySqlConnection.
Public method MySqlCommand(String, MySqlConnection, MySqlTransaction)
Initializes a new instance of the MySqlCommand class with the text of the query, a MySqlConnection, and the MySqlTransaction.

Examples

The following example creates a MySqlCommand and sets some of its properties.

Note
This example shows how to use one of the overloaded versions of the MySqlCommand constructor. For other examples that might be available, see the individual overload topics.
Visual Basic Copy imageCopy
Public Sub CreateMySqlCommand()
Dim myConnection As New MySqlConnection _
("Persist Security Info=False;database=test;server=myServer")
myConnection.Open()
Dim myTrans As MySqlTransaction = myConnection.BeginTransaction()
Dim mySelectQuery As String = "SELECT * FROM MyTable"
Dim myCommand As New MySqlCommand(mySelectQuery, myConnection, myTrans)
myCommand.CommandTimeout = 20
End Sub
C# Copy imageCopy
public void CreateMySqlCommand()
{
MySqlConnection myConnection = new MySqlConnection("Persist Security Info=False;
database=test;server=myServer");
myConnection.Open();
MySqlTransaction myTrans = myConnection.BeginTransaction();
string mySelectQuery = "SELECT * FROM myTable";
MySqlCommand myCommand = new MySqlCommand(mySelectQuery, myConnection,myTrans);
myCommand.CommandTimeout = 20;
}
Visual C++ Copy imageCopy
public:
void CreateMySqlCommand()
{
MySqlConnection* myConnection = new MySqlConnection(S"Persist Security Info=False;
database=test;server=myServer");
myConnection->Open();
MySqlTransaction* myTrans = myConnection->BeginTransaction();
String* mySelectQuery = S"SELECT * FROM myTable";
MySqlCommand* myCommand = new MySqlCommand(mySelectQuery, myConnection, myTrans);
myCommand->CommandTimeout = 20;
};

See Also