SqlCeDataReader Class
Assembly: System.Data.SqlServerCe (in system.data.sqlserverce.dll)
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.
System.MarshalByRefObject
System.Data.Common.DbDataReader
System.Data.SqlServerCe.SqlCeDataReader
System.Data.SqlServerCe.SqlCeResultSet
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.
SqlCeConnection conn = null; SqlCeCommand cmd = null; SqlCeDataReader rdr = null; try { // Open the connection and create a SQL command // conn = new SqlCeConnection("Data Source = AdventureWorks.sdf"); conn.Open(); 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 // rdr.Close(); cmd.Dispose(); } finally { // Close the connection when no longer needed // conn.Close(); }
Development Platforms
Windows Vista, Windows Mobile 5.0, Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Mobile 2003 for Pocket PC, Windows CE 5.0Version Information
.NET Framework and NET Compact Framework
Supported in 3.5
.NET Framework
Supported in 3.0
.NET Compact Framework and .Net Framework
Supported in 2.0