dotConnect for Adobe Commerce Documentation
Devart.Data.Magento Namespace / MagentoCommand Class / ExecuteReader Method / ExecuteReader() Method
Example

On this page
    ExecuteReader() Method
    On this page
    Sends the CommandText to the Connection and builds a MagentoDataReader.
    Syntax
    'Declaration
     
    Public Overloads Shadows Function ExecuteReader() As MagentoDataReader
    public new MagentoDataReader ExecuteReader()

    Return Value

    Example
    The following example creates a MagentoCommand, then executes it by passing a string that is SQL SELECT statement, and a string to use to connect to the data source.
    public void CreateMagentoDataReader(string mySelectQuery,string magentoConnectionString)
    {
      MagentoConnection magentoConnection = new MagentoConnection(magentoConnectionString);
      MagentoCommand magentoCommand = new MagentoCommand(mySelectQuery, magentoConnection);
      magentoCommand.Connection.Open();
      MagentoDataReader magentoReader = magentoCommand.ExecuteReader();
      try
      {
        while(magentoReader.Read())
        {
          Console.WriteLine(magentoReader.GetString(0));
        }
      }
      finally
      {
        magentoReader.Close();
        magentoConnection.Close();
      }
    }
    Public Sub CreateMagentoDataReader(mySelectQuery As String, _
    magentoConnectionString As String)
      Dim magentoConnection As New MagentoConnection(magentoConnectionString)
      Dim magentoCommand As New MagentoCommand(mySelectQuery, magentoConnection)
      magentoCommand.Connection.Open()
      Dim magentoReader As MagentoDataReader = magentoCommand.ExecuteReader()
      Try
        While magentoReader.Read()
          Console.WriteLine(magentoReader.GetString(0))
        End While
      Finally
        magentoReader.Close()
        magentoConnection.Close()
      End Try
    End Sub
    See Also