dotConnect for MySQL Documentation
Devart.Data.MySql Namespace / MySqlConnection Class / CreateCommand Method
Example

In This Topic
    CreateCommand Method (MySqlConnection)
    In This Topic
    Creates and returns a MySqlCommand object associated with the MySqlConnection.
    Creates and returns a MySqlCommand object associated with the MySqlConnection.
    Syntax
    'Declaration
     
    Public Shadows Function CreateCommand() As MySqlCommand
    public new MySqlCommand CreateCommand()

    Return Value

    A MySqlCommand object.
    Remarks
    You can use this method as an alternative to common MySqlCommand constructors.
    Example
    In this sample MySqlCommand object is created. It is automatically associated with MySqlConnection that created it.
    public void CreateMySqlCommand(string myConnString)
    {
      MySqlConnection myConnection = new MySqlConnection(myConnString);
      MySqlCommand myCommand = myConnection.CreateCommand();
      myCommand.CommandText = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')";
      myConnection.Open();
      try
      {
        myCommand.ExecuteNonQuery();
      }
      finally
      {
        myConnection.Close();
      }
    }
    Public Sub CreateMySqlCommand(ByVal myConnString As String)
      Dim myConnection As New MySqlConnection(myConnString)
      Dim myCommand As MySqlCommand = myConnection.CreateCommand()
      myCommand.CommandText = "INSERT INTO DEPT VALUES (50,'Development','Philadelphia')"
      myConnection.Open()
      Try
        myCommand.ExecuteNonQuery()
      Finally
        myConnection.Close()
      End Try
    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