dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlCommand Class / Connection Property
Example

In This Topic
    Connection Property (MySqlCommand)
    In This Topic
    Gets or sets the MySqlConnection used by this instance of the MySqlCommand.
    Syntax
    'Declaration
     
    Public Shadows Property Connection As MySqlConnection
    public new MySqlConnection Connection {get; set;}

    Property Value

    The connection to a data source. The default value is a null reference.
    Remarks

    MySqlConnection specified in this property will carry out all operations executed with this MySqlCommand.

    This property supports the InterForm technology.

    A single MySqlConnection can be used by many MySqlCommand objects on the assumption that all operations will be done consecutively. In other words, you can not execute an SQL statement while an asynchronous operation is in progress.

    Example
    The following example creates a MySqlCommand and sets some of its properties.
    public void CreateCommand()
    {
      string mySelectQuery = "SELECT * FROM Test.Dept ORDER BY DeptNo";
      MySqlCommand myCommand = new MySqlCommand(mySelectQuery);
      myCommand.Connection = new MySqlConnection(
        "User Id=root;Host=localhost;Database=Test;");
      myCommand.CommandType = System.Data.CommandType.Text;
    }
    Public Sub CreateCommand()
      Dim mySelectQuery As String = _
        "SELECT * FROM Test.Dept ORDER BY DeptNo"
      Dim myCommand As New MySqlCommand(mySelectQuery)
      myCommand.Connection = New MySqlConnection( _
        "User Id=root;Host=localhost;Database=Test;")
      myCommand.CommandType = System.Data.CommandType.Text
    End Sub
    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also