Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6668933
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:05:39+00:00 2026-05-26T03:05:39+00:00

The IDataReader interface inherits from IDataRecord. The Read() method changes the state of the

  • 0

The IDataReader interface inherits from IDataRecord. The Read() method changes the state of the reader so that you can retrieve the fields:

var reader = new SomeIDataReader();
while (reader.Read()) {
    var firstField = reader[0];
}

The IDataReader contains both the reader and the record. In my opinion, this mixes two concerns in one class. I would return a record object, and use it like this:

var reader = new MyDataReader();
do {
    var record = reader.Read();
    if (record == null) break;
    var firstField = record[0];
} while (true);

This separates the concerns of data reader and data container, and makes it possible to read from the same source using two threads.

Is my solution better? What are some advantages of letting the reader contain the result? Why would anyone choose for the IDataReader approach?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T03:05:40+00:00Added an answer on May 26, 2026 at 3:05 am

    One disadvantage of having a separate record object is that a naive caller might think he could pass it around and use it independently of the underlying IDataReader.

    I.e. he might think he could get an IDataRecord while the reader is positioned at the first record, and use it to reference the first record when the reader has moved on or even been closed. This is patently impossible without the overhead of materializing the record, which goes against the high-performance forward-only concept of a reader.

    I don’t pretend to understand all the thought processes that went into the design decision, but I’m sure it was carefully considered and is the right design (‘right’ in the sense of ‘best trade-off’ rather than ‘perfect’).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need a C# method that can pivot a DataTable/IDataReader object where the source
I know that IDataReader is a interface so I can't create an instance of
How do I return null value from a generic method? protected T ValueOrDefault<T>(IDataReader reader,
How can I make sure in the following code snippet that IDataReader is disposed
I found that the mapping is a case sensitive mapping from IDataReader which is
string SQL = SELECT TOP 1 * FROM + TableName; IDataReader reader = DatabaseClassCreator.ExecSQLReader(,
I'm trying to fill a collection from an IDataReader that was returned by another
AFAIK you can load one DataSet from another DataSet via IDataReader i.e. new DataSet().Load(existingDataSet.CreateDataReader());
How do I mock the method GetValues() in System.Data.IDataReader? This method changes the array
(LocalVariable)ABC.string(Name) = (IDataReader)dataReader.GetString(0); This name value is coming from database. What happening here is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.