Question - Name some of the properties and methods provided by the DataReader in ADO.NET?
Answer -
Some of the properties provided by the DataReader are as follows:
- Depth: It represents the depth of nesting for a row.
- FieldCount: It gives the total column count in a row.
- Item: It obtains the column value in a native format.
- RecordsAffected: It gives the number of transaction affected rows.
- IsClosed: It represents whether a data reader is closed.
- VisibleFieldCount: It is used to obtain the number of unhidden fields in the SqlDataReader.
Some of the methods provided by the DataReader are as follows:
- Read(): This method reads a record from the SQL Server database.
- Close(): It closes a SqlDataReader object.
- NextResult(): It moves the data reader to the next result during the time of batch transactions.
- Getxxx(): Various types of Getxxx() methods such as GetBoolean(Int32), GetChar(Int32), GetFloat(Int32), GetDouble(Int32), etc., are provided by the DataReader. These methods will read a value of a particular data type from a column. For example, GetFloat() will return a column value as a Float and GetChar as a character.