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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T07:51:47+00:00 2026-06-17T07:51:47+00:00

I had following Service method – public static DataTable GetBookDetails(BookEntities context) { DataTable dtBooks=

  • 0

I had following Service method –

public static DataTable GetBookDetails(BookEntities context)
    {
        DataTable dtBooks= new DataTable();
        dtBooks.TableName = "BookDetails";
        dtBooks.Columns.Add(new DataColumn("Name",typeof(string)));
        dtBooks.Columns.Add(new DataColumn("ISBN",typeof(string)));
        dtBooks.Columns.Add(new DataColumn("Price",typeof(int)));
        dtBooks.Columns.Add(new DataColumn("Author",typeof(string)));
        IQueryable<Book> query = from b in context.Books.Include("Authors")
                                                                      .Include("Details/Price")
                                                                      .Include("Activity")
                                     where b.Activity.IsActive
                                     select b;
        if (query != null)
        {
            var sorted = query.ToArray().OrderByDescending(b => b.Activity.DateCreated);
            foreach (Book bb in sorted)
            {
                DataRow row = dtBooks.NewRow();
                row["Name"] = bb.Name;
                row["ISBN"] = bb.ISBN;
                row["Price"] = bb.Details.Price.CostOfBook;
                row["Author"] = bb.Authors.Name;
                dtBooks.Rows.Add(row);
            }
        }
        else
            dtBooks= null;
        return dtBooks;
    }

My Questions are –

  1. Is this an efficient way to get details or can I improve this method?
  2. Someone suggested me to use IList instead of DataTable. Should I use this? If so, what are the advantages?
  3. What’s wrong in using DataTable?
  • 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-06-17T07:51:48+00:00Added an answer on June 17, 2026 at 7:51 am

    DataTable vs IList

    IList represent collection that can be accessed by index. Nothing more.

    DataTable also has similar capabilities, but it provides much more functionality (like more events, More features) and is suitable where these features are required like representing Tabular data with advance capabilities (binding, custom sorting, grouping, event for row changed, cell added etc). All these extra features comes at extra overhead (of more memory requirement).

    Is this the efficient way to get details or I can improve this method?

    You can slightly improve by using IList. The improvement is not in faster data access, but in not using extra features that DataTable provides.If you dont require access by index, you can further improve by using IEnumerable.
    You can further improve upon by using generics version. IList<T>, or IEnumerable<T> to save upon boxing/unboxing overhead.

    Someone suggested me to use IList instead of DataTable. Should I use this? If so, what are the advantages?

    IList does not have overhead of plethora of features provided by DataTable other than access by index.

    Whats wrong in using DataTable?

    Nothing wrong. DataTable is more suitable where advanced data access features are required.

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

Sidebar

Related Questions

I had the following set-up which worked perfectly fine: @Service public class MyService {
I had a method: @POST @Consumes(multipart/form-data) @Produces( {text/xml}) public Response processForm( @FormDataParam(myparam) InputStream is,
I am having a RESTful service with the following method: [WebInvoke] string GetDataFromStringAsString(string xmlString);
I had following cgridview in Yii application, I want to change date format in
I had the following query that doesn't work and I was wondering how to
I had the following template that essentially changed the color of the border of
I had the following idea: Say we have a webapp written using django which
I had the following problem today, and I was wondering if there is a
I had the following HTML page rendering to use the Google Maps API. This
I initially had the following code: Boolean successCheckPoint = false; Boolean failureCheckPoint = false;

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.