dotConnect for Adobe Commerce Documentation
Devart.Data.Magento Namespace / MagentoDataReader Class
Members Example

In This Topic
    MagentoDataReader Class
    In This Topic
    Reads a forward-only stream of rows from Adobe Commerce.
    Syntax
    Remarks
    To create a MagentoDataReader, you must call the ExecuteReader method of the MagentoCommand object, rather than directly using a constructor.

    System.Data.Common.DbDataReader.IsClosed and Devart.Data.SqlShimDataReader.RecordsAffected are the only properties that you can call after the MagentoDataReader is closed. In some cases, you must call Devart.Data.SqlShimDataReader.Close before you can call Devart.Data.SqlShimDataReader.RecordsAffected.

    Example
    The following example creates a MagentoConnection, a MagentoCommand, and a MagentoDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the MagentoDataReader, then the MagentoConnection.
    public void ReadMyData(string myConnString)  {
            MagentoConnection adobe commerceConnection = new MagentoConnection(myConnString);
            MagentoCommand adobe commerceCommand = (MagentoCommand)adobe commerceConnection.CreateCommand();
            adobe commerceCommand.CommandText = "SELECT customer_id, firstname, lastname FROM Customers";
            adobe commerceConnection.Open();
            MagentoDataReader adobe commerceReader = adobe commerceCommand.ExecuteReader();
            try {
                    // Always call Read before accessing data.
                    while (adobe commerceReader.Read()) {
                    Console.WriteLine(adobe commerceReader.GetInt32(0).ToString() + " " + 
                    adobe commerceReader.GetString(1) + " " + adobe commerceReader.GetString(2));
            }
            }
            finally {
                    // always call Close when done reading.
                    adobe commerceReader.Close();
    
                    // Close the connection when done with it.
                    adobe commerceConnection.Close();
            }
    }
    Public Sub ReadMyData(ByVal myConnString As String)
            Dim adobe commerceConnection As New MagentoConnection(myConnString)
            Dim adobe commerceCommand As MagentoCommand = adobe commerceConnection.CreateCommand()
                    adobe commerceCommand.CommandText = "SELECT customer_id, firstname, lastname FROM Customers"
            adobe commerceConnection.Open()
            Dim adobe commerceReader As MagentoDataReader = adobe commerceCommand.ExecuteReader()
            Try
                    ' Always call Read before accessing data.
                    While adobe commerceReader.Read()
                            Console.WriteLine(String.Concat(adobe commerceReader.GetInt32(0).ToString(), " ", _
                            adobe commerceReader.GetString(1), " ", adobe commerceReader.GetString(2)))
                    End While
            Finally
                    ' always call Close when done reading.
                    adobe commerceReader.Close()
    
                            ' Close the connection when done with it.
                            adobe commerceConnection.Close()
            End Try
    End Sub
    Inheritance Hierarchy

    System.Object
       System.MarshalByRefObject
          System.Data.Common.DbDataReader
             Devart.Common.DbDataReaderBase
                Devart.Data.SqlShimDataReader
                   Devart.Data.Magento.MagentoDataReader

    See Also