dotConnect for Dynamics 365 Documentation
Devart.Data.Dynamics Namespace / DynamicsDataReader Class
Members Example

In This Topic
    DynamicsDataReader Class
    In This Topic
    Reads a forward-only stream of rows from Dynamics CRM.
    Syntax
    Remarks
    To create a DynamicsDataReader, you must call the ExecuteReader method of the DynamicsCommand object, rather than directly using a constructor.

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

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

    System.Object
       System.MarshalByRefObject
          System.Data.Common.DbDataReader
             Devart.Common.DbDataReaderBase
                Devart.Data.SqlShimDataReader
                   Devart.Data.Dynamics.DynamicsDataReader

    Requirements

    Target Platforms: Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

    See Also