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

In This Topic
    CreateCommand Method (MagentoConnection)
    In This Topic
    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 adobe commerceConnection = new MagentoConnection(myConnString);
      MagentoCommand adobe commerceCommand = adobe commerceConnection.CreateCommand();
      adobe commerceCommand.CommandText = "INSERT INTO Customers (email, firstname, lastname) VALUES ('[email protected]', 'John', 'Smith')";
      adobe commerceConnection.Open();
      try
      {
        adobe commerceCommand.ExecuteNonQuery();
      }
      finally
      {
        adobe commerceConnection.Close();
      }
    }
    Public Sub CreateMagentoCommand(ByVal myConnString As String)
      Dim adobe commerceConnection As New MagentoConnection(myConnString)
      Dim adobe commerceCommand As MagentoCommand = adobe commerceConnection.CreateCommand()
      adobe commerceCommand.CommandText = "INSERT INTO Customers (email, firstname, lastname) VALUES ('[email protected]', 'John', 'Smith')"
      adobe commerceConnection.Open()
      Try
        adobe commerceCommand.ExecuteNonQuery()
      Finally
        adobe commerceConnection.Close()
      End Try
    End Sub
    See Also