Provides a way of reading a forward-only stream of rows from a SQL Server database.
The SqlDataReader
is a member of the .NET framework's System.Data.SqlClient
family responsible for reading data from a SQL database. The SqlDataReader
is created by calling the ExecuteReader()
method of the SqlCommand
object, instead of directly using a constructor.
While the SqlDataReader
is being used, the associated SqlConnection
is busy serving the SqlDataReader
, and no other operations can be performed on the SqlConnection
other than closing it. This is the case until the Close
method of the SqlDataReader
is called. For example, you cannot retrieve output parameters until after you call Close.
Changes made to a result set by another process or thread while data is being read may be visible to the user of the SqlDataReader
. However, the precise behavior is timing dependent.
For optimal performance, SqlDataReader
avoids creating unnecessary objects or making unnecessary copies of data. Therefore, multiple calls to methods such as GetValue
return a reference to the same object. Use caution if you are modifying the underlying value of the objects returned by methods such as GetValue
.