dotConnect for Adobe Commerce Documentation
Devart.Data Namespace / SqlShimDataReader Class / Read Method
Example

On this page
    Read Method (SqlShimDataReader)
    On this page
    Advances the SqlShimDataReader to the next record.
    Syntax
    'Declaration
     
    Public Overrides Function Read() As Boolean
    public override bool Read()

    Return Value

    true if there are more rows; otherwise, false.
    Remarks
    The default position of the SqlShimDataReader is prior to the first record. Therefore, you must call Read to begin accessing any data.

    While the SqlShimDataReader is in use, the associated Devart.Data.Magento.MagentoConnection is busy serving it until you call Close.

    Example
    The following example creates a Devart.Data.Magento.MagentoConnection, a Devart.Data.Magento.MagentoCommand, and a SqlShimDataReader. The example reads through the data, writing it out to the console. Finally, the example closes the SqlShimDataReader, then the Devart.Data.Magento.MagentoConnection.
    public void ReadMyData(string myConnString)
    {
      string mySelectQuery = "SELECT customer_id, lastname FROM Customers";
      MagentoConnection magentoConnection = new MagentoConnection(myConnString);
      MagentoCommand magentoCommand = new MagentoCommand(mySelectQuery,magentoConnection);
      magentoConnection.Open();
      MagentoDataReader magentoReader;
      magentoReader = magentoCommand.ExecuteReader();
      // Always call Read before accessing data.
      while (magentoReader.Read()) {
        Console.WriteLine(magentoReader.GetString(0) + ", " + magentoReader.GetString(1));
      }
      // always call Close when done reading.
      magentoReader.Close();
      // Close the connection when done with it.
      magentoConnection.Close();
    }
    Public Sub ReadMyData(myConnString As String)
      Dim mySelectQuery As String = "SELECT customer_id, lastname FROM Customers"
      Dim magentoConnection As New MagentoConnection(myConnString)
      Dim magentoCommand As New MagentoCommand(mySelectQuery, magentoConnection)
      magentoConnection.Open()
      Dim magentoReader As MagentoDataReader
      magentoReader = magentoCommand.ExecuteReader()
      ' Always call Read before accessing data.
      While magentoReader.Read()
        Console.WriteLine(magentoReader.GetString(0) + ", " _
          + magentoReader.GetString(1))
      End While
      ' always call Close when done reading.
      magentoReader.Close()
      ' Close the connection when done with it.
      magentoConnection.Close()
    End Sub
    See Also