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

  • SEARCH
  • Home
  • 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 6914207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T09:19:03+00:00 2026-05-27T09:19:03+00:00

Is dataReader[i] logically equivalent to dataReader.GetValue(i) Are they the same? Are they different? Is

  • 0

Is

dataReader[i]

logically equivalent to

dataReader.GetValue(i)

Are they the same? Are they different? Is there a situation where one would be appropriate over the other?

There are documented differently:

  • Gets the column located at the specified index
  • Return the value of the specified field.

But when i use them they both return the value of the field. What does it mean to “get the column”? What does it mean to “return the value of a field”?


Bonus Chatter:

When I call:

reader[i];
reader.GetValue(i);
reader.GetString(i);

i get a String each time

  • 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-27T09:19:03+00:00Added an answer on May 27, 2026 at 9:19 am

    Ultimately it depends on the particular implementation of System.Data.IDataReader you are referring to, but let’s assume you mean System.Data.SqlClient.SqlDataReader.

    In this case, reader[i] and reader.GetValue(i) do exactly the same thing. In fact, reader[i] internally calls reader.GetValue(i). (You can see this by disassembling the code using a tool like ILSpy.). Both these members return the value in the i-th column of the current row and will return successfully regardless of the type of the value (the return type is object). The documentation for both of these members is a little misleading and could be worded in a better way. You can use either of these members wherever you like, just pick the one which you feel reads better.

    Whereas reader.GetString(i) is specifically designed to return the value contained in the i-th column of the current row as a string. If the value in that column is not a string, an InvalidCastException will be thrown. Use this method when you are sure that the value is a string and string is the type that you want to work with. This will make your code more concise since you won’t have to perform a cast.

    In your specific case, the value in the i-th column of the current row must be of type string, which is why the return value of all three members is identical.

    If written correctly, other implementations of System.Data.IDataReader should behave in the same way.

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

Sidebar

Related Questions

Can I avoid the open DataReader exception (There is already an open DataReader associated
When returning data from a DataReader I would typically use the ordinal reference on
runtime error 'there is already an open datareader associated with this command which must
I have 20 different methods and use datareader to read and get result from
I have a sql datareader...From which I have to fetch one decimal value. What
I have a sql datareader...From which I have to fetch one decimal value. What
Which would be quicker. 1) Looping a datareader and creating a custom rows and
Is there a difference between DataReader[0].ToString() and (string)DataReader[0] ? My guess is that (string)DataReader[0]
I can create ab object in .NET 4, run a DataReader over a sproc
The DataReader is more efficient than a DataTable if you only need to show

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.