0% found this document useful (0 votes)
21 views

SqlDataReader Class in ADO

The document discusses the SqlDataReader class in ADO.Net. It can only be used to read data and not update or delete. It provides a connection-oriented way to access SQL Server data from C# applications. The ExecuteReader method of the SqlCommand populates a SqlDataReader object based on a SQL statement or stored procedure. SqlDataReader is read-only and the connection needs to be explicitly opened and closed. It is useful for displaying query results due to its performance advantages of buffering data on the client side. Key properties and methods like Read, FieldCount and Item are described.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
21 views

SqlDataReader Class in ADO

The document discusses the SqlDataReader class in ADO.Net. It can only be used to read data and not update or delete. It provides a connection-oriented way to access SQL Server data from C# applications. The ExecuteReader method of the SqlCommand populates a SqlDataReader object based on a SQL statement or stored procedure. SqlDataReader is read-only and the connection needs to be explicitly opened and closed. It is useful for displaying query results due to its performance advantages of buffering data on the client side. Key properties and methods like Read, FieldCount and Item are described.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 10

SqlDataReader Class in

ADO.Net
PRESENTER: MOHAMMAD ADIL
A DO.Net SqlDataReader Class With Different Data Providers
Signature SqlDataReader
ADO.Net SqlDataReader Class
• It means you can only read and display data but can’t update or
delete data.
• If you want to make modification in retrieved data you need to use
DataAdapter instead of DataReader.
• SqlDataReader Object provides a connection oriented data access
to the SQL Server data Sources from C# applications.
• ExecuteReader() in the SqlCommand Object sends the SQL
statements to the SqlConnection Object and populate a
SqlDataReader Object based on the SQL statement or Stored
Procedures.
ADO.Net SqlDataReader Class
• Object of SqlDataReader cannot be created using new keyword.
• SqlDataReader dr = new SqlDataReader();
• ExecuteReader() method of SqlCommand create and returns an
object of SqlDataReader.
• SqlDataReader is read-only. It means it is also not possible to
change the data using SqlDataReader.
• You also need to open and close the connection explicitly.
WHY AND WHEN TO USE DATAREADER?
• When you want to only display information or search result, you can
use DataReader. There are various advantages of using DataReader
like:
• 1. The retrieved data is stored in the network buffer in the client
and then the client can read data using Read method. As data gets
stored in the client network buffer it increases application
performance significantly.
• 2. By default DataReader stores only one row at a time in memory.
It reduces system overhead.
Properties Of SqlDataReader Class
• FieldCount (int): It gets the number of columns in the current row.
• HasRows (boolean): It gets a value that indicates whether the
System.Data.SqlClient.SqlDataReader contains one or more rows.
• IsClosed: It retrieves a Boolean value that indicates whether the
specified System.Data.SqlClient.SqlDataReader instance has been
closed
• Item[String]: It gets the value of the specified column in its native
format given the column name.
• Item[Int32]: It gets the value of the specified column in its native
format given the column ordinal.
Methods Of SqlDataReader Class
• Read(): It Advances the System.Data.SqlClient.SqlDataReader to the
next record and returns true if there are more rows; otherwise false
You can read data by using concatenation and placeholder syntax in
console application.
• GetName(int i): It gets the name of the specified column. Here,
parameter i is the zero-based column ordinal.
• NextResult(): It advances the data reader to the next result when
reading the results of batch Transact-SQL statements.

You might also like