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 7569377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T15:09:02+00:00 2026-05-30T15:09:02+00:00

I know that IDataReader is a interface so I can’t create an instance of

  • 0

I know that IDataReader is a interface so I can’t create an instance of interface.

However, it is possible to get instances of IdataReader.

How can this be possible?

  • 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-30T15:09:03+00:00Added an answer on May 30, 2026 at 3:09 pm

    You cannot create an instance of an Interface. But you can create an instance of a class that implements an interface. In case of IDataReader SqlDataReader is an implementation.

    You get an instance by executing a SqlCommand:

    SqlDataReader reader = command.ExecuteReader();
    

    For example (from MSDN):

    string queryString =
        "SELECT OrderID, CustomerID FROM dbo.Orders;";
    
    using (SqlConnection connection =
               new SqlConnection(connectionString))
    {
        SqlCommand command =
            new SqlCommand(queryString, connection);
        connection.Open();
    
        // here is your SqlDataReader that implements IDataReader
        SqlDataReader reader = command.ExecuteReader();
    
        // Call Read before accessing data.
        while (reader.Read())
        {
            Console.WriteLine(String.Format("{0}, {1}",
                reader[0], reader[1]));
        }
    
        // Call Close when done reading.
        reader.Close();
    }
    

    Edit:

    I assume that you don’t understand why it’s possible to have an instance that has the type of an interface. That is no contradiction since an interface actually is a type.

    So if i would create a class, say MyDataReader, that implements IDataReader, an instance of my class would be of type MyDataReader as well as IDataReader.

    If anybody would create an instance of MyDataReader, he knows that it also implements all methods of IDataReader. That is important for Polymorphism.

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

Sidebar

Related Questions

I know that the MsNLB can be configured to user mulitcast with IGMP. However,
I know that I can use ProxyPass to serve up my yardoc server instance
I know that I can do something like $int = (int)99; //(int) has a
I know that you can insert multiple rows at once, is there a way
I know that IList is the interface and List is the concrete type but
I know that this isn't exactly normalised, but bringing all of the localised data
i know that the LinkedHashMap provides a constructor, where you can indicate if the
I know that in C# you can nowadays do: var a = new MyObject
I know that this may be common knowledge, but is there a way to
I know that default cron's behavior is to send normal and error output to

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.