Net-informations.com
SiteMap  | About    

C# ADO.NET DataReader

DataReader Object in ADO.NET is a stream-based , forward-only, read-only retrieval of query results from the Data Sources , which do not update the data. The DataReader cannot be created directly from code, they can created only by calling the ExecuteReader method of a Command Object.

csharp-datareader.JPG
  SqlDataReader sqlReader = sqlCmd.ExecuteReader();

The DataReader Object provides a connection oriented data access to the Data Sources. A Connection Object can contain only one DataReader at a time and the connection in the DataReader remains open, also it cannot be used for any other purpose while data is being accessed. When we started to read from a DataReader it should always be open and positioned prior to the first record. The Read() method in the DataReader is used to read the rows from DataReader and it always moves forward to a new valid row, if any row exist .

  DataReader.Raed(); 

Usually we are using two types of DataReader in ADO.NET. They are SqlDataReader and the OleDbDataReader . The System.Data.SqlClient and System.Data.OleDb are containing these DataReaders respectively. From the following link you can see in details about these classes in C#.

C# SqlDataReader

C# OleDbDataReader









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.