dotConnect for SugarCRM Documentation
Devart.Data.Sugar Namespace / SugarDataReader Class
Members Example

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

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

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

    System.Object
       System.MarshalByRefObject
          System.Data.Common.DbDataReader
             Devart.Common.DbDataReaderBase
                Devart.Data.SqlShimDataReader
                   Devart.Data.Sugar.SugarDataReader

    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