dotConnect for Adobe Commerce Documentation
Devart.Data.Magento Namespace / MagentoConnection Class / CreateCommand Method
Example

On this page
    CreateCommand Method (MagentoConnection)
    On this page
    Creates and returns a MagentoCommand object associated with the MagentoConnection.
    Creates and returns a MagentoCommand object associated with the MagentoConnection.
    Syntax
    'Declaration
     
    Public Shadows Function CreateCommand() As MagentoCommand
    public new MagentoCommand CreateCommand()

    Return Value

    A MagentoCommand object.
    Remarks
    You can use this method as an alternative to common MagentoCommand constructors.
    Example
    In this sample MagentoCommand object is created. It is automatically associated with MagentoConnection that created it.
    public void CreateMagentoCommand(string myConnString)
    {
      MagentoConnection magentoConnection = new MagentoConnection(myConnString);
      MagentoCommand magentoCommand = magentoConnection.CreateCommand();
      magentoCommand.CommandText = "INSERT INTO Customers (email, firstname, lastname) VALUES ('[email protected]', 'John', 'Smith')";
      magentoConnection.Open();
      try
      {
        magentoCommand.ExecuteNonQuery();
      }
      finally
      {
        magentoConnection.Close();
      }
    }
    Public Sub CreateMagentoCommand(ByVal myConnString As String)
      Dim magentoConnection As New MagentoConnection(myConnString)
      Dim magentoCommand As MagentoCommand = magentoConnection.CreateCommand()
      magentoCommand.CommandText = "INSERT INTO Customers (email, firstname, lastname) VALUES ('[email protected]', 'John', 'Smith')"
      magentoConnection.Open()
      Try
        magentoCommand.ExecuteNonQuery()
      Finally
        magentoConnection.Close()
      End Try
    End Sub
    See Also