SqlCeDataReader Class

Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited.

Namespace: System.Data.SqlServerCe
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)


Public Class SqlCeDataReader
    Inherits DbDataReader
Dim instance As SqlCeDataReader
public class SqlCeDataReader : DbDataReader
public ref class SqlCeDataReader : public DbDataReader
public class SqlCeDataReader extends DbDataReader
public class SqlCeDataReader extends DbDataReader


To create a SqlCeDataReader, you must call the ExecuteReader method of the SqlCeCommand object, rather than directly using a constructor.

While the SqlCeDataReader is in use, the associated SqlCeConnection is busy serving the SqlCeDataReader. In this state, you can create multiple readers in the same connection.

Changes made to a result set by another process or thread while the data is being read may be visible to the user of the SqlCeDataReader; however, the precise behavior is dependent on when these occur.

IsClosed and RecordsAffected are the only properties you can call after the SqlCeDataReader is closed. Although the RecordsAffected property can be accessed at any time while the SqlCeDataReader exists, always call Close before returning the value of RecordsAffected to ensure an accurate return value.


The following example creates a SqlCeConnection, a SqlCeCommand, and a SqlCeDataReader. The example reads through the data and writes it out to the console, and then closes the SqlCeDataReader and the SqlCeConnection.

Dim conn As SqlCeConnection = Nothing
Dim cmd As SqlCeCommand = Nothing
Dim rdr As SqlCeDataReader = Nothing

    ' Open the connection and create a SQL command
    conn = New SqlCeConnection("Data Source = AdventureWorks.sdf")
    cmd = New SqlCeCommand("SELECT * FROM DimEmployee", conn)
    rdr = cmd.ExecuteReader()
    ' Iterate through the results
    While rdr.Read()
        Dim employeeID As Integer = rdr.GetInt32(0) ' or: rdr["EmployeeKey"];
        Dim lastName As String = rdr.GetString(5) ' or: rdr["FirstName"];
    End While
    ' Always dispose data readers and commands as soon as practicable
    ' Close the connection when no longer needed
End Try
SqlCeConnection conn = null;
SqlCeCommand cmd = null;
SqlCeDataReader rdr = null;

    // Open the connection and create a SQL command
    conn = new SqlCeConnection("Data Source = AdventureWorks.sdf");

    cmd = new SqlCeCommand("SELECT * FROM DimEmployee", conn);

    rdr = cmd.ExecuteReader();

    // Iterate through the results
    while (rdr.Read())
        int employeeID = rdr.GetInt32(0);   // or: rdr["EmployeeKey"];
        string lastName = rdr.GetString(5); // or: rdr["FirstName"];

    // Always dispose data readers and commands as soon as practicable

    // Close the connection when no longer needed

Inheritance Hierarchy


Thread Safety

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.


Windows CE, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows XP Professional x64 Edition, Windows XP SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

Version Information

.NET Compact Framework

Supported in: 2.0, 1.0

See Also


SqlCeDataReader Members
System.Data.SqlServerCe Namespace