Provides a way of reading a forward-only stream of data rows from a data source. This class cannot be inherited.
For a list of all members of this type, see SqlCeDataReader Members.
System.Object
System.MarshalByRefObject
System.Data.SqlServerCe.SqlCeDataReader
[Visual Basic] NotInheritable Public Class SqlCeDataReader Inherits MarshalByRefObject Implements IDataReader, IDisposable, IDataRecord [C#] public sealed class SqlCeDataReader : MarshalByRefObject, IDataReader, IDisposable, IDataRecord [C++] public __gc __sealed class SqlCeDataReader : public MarshalByRefObject, IDataReader, IDisposable, IDataRecord [JScript] public class SqlCeDataReader extends MarshalByRefObject implements IDataReader, IDisposable, IDataRecord
Any public static (Shared in Visual Basic) members of this type are safe for multithreaded operations. Any instance members are not guaranteed to be thread safe.
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 that 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.
[Visual Basic, C#] 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.
[Visual Basic] Public Sub ReadMyData(myConnString As String) Dim mySelectQuery As String = "SELECT OrderID, CustomerID FROM Orders" Dim myConnection As New SqlCeConnection(myConnString) Dim myCommand As New SqlCeCommand(mySelectQuery, myConnection) myConnection.Open() Dim myReader As SqlCeDataReader myReader = myCommand.ExecuteReader() ' Always call Read before accessing data. While myReader.Read() Console.WriteLine((myReader.GetInt32(0) & ", " & myReader.GetString(1))) End While ' always call Close when done reading. myReader.Close() ' Close the connection when done with it. myConnection.Close() End Sub 'ReadMyData [C#] public void ReadMyData(string myConnString) { string mySelectQuery = "SELECT OrderID, CustomerID FROM Orders"; SqlCeConnection myConnection = new SqlCeConnection(myConnString); SqlCeCommand myCommand = new SqlCeCommand(mySelectQuery,myConnection); myConnection.Open(); SqlCeDataReader myReader; myReader = myCommand.ExecuteReader(); // Always call Read before accessing data. while (myReader.Read()) { Console.WriteLine(myReader.GetInt32(0) + ", " + myReader.GetString(1)); } // always call Close when done reading. myReader.Close(); // Close the connection when done with it. myConnection.Close(); }
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Namespace: System.Data.SqlServerCe
Platforms: .NET Compact Framework - Windows CE .NET
Assembly: System.Data.Sqlserverce (in System.Data.Sqlserverce.dll)