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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T17:34:08+00:00 2026-05-26T17:34:08+00:00

I am created List of object class and return from CreateListFromTable method. But always

  • 0

I am created List of object class and return from CreateListFromTable method. But always Virtual method is calling and throwing exception. Data is not loading into List.

What could be the problem?

 public static List<Customer> GetCustomer(string ID)
    {
        DataTable dt = new DataTable();
        try
        {
            DatabaseGateway da = new DatabaseGateway();
            dt = da.QueryForDataTable("proc_GetCustomer", ID);                
        }
        catch (Exception ex)
        {
            LogMessage(ex.Message + ":  " + ex.StackTrace, EventLogEntryType.Error);
        }

        return CreateListFromTable<Customer>(dt);          


    }

 protected static List<T> CreateListFromTable<T>(DataTable dt) where T : BusinessObject, new()
    {
        List<T> list = new List<T>();
        try
        {          
            if (dt != null)
            foreach (DataRow row in dt.Rows)
            {
                T t = new T();
                t.Load(row);
                list.Add(t);
            }
        }
        catch (Exception exception)
        {


        }
        return list;
    }
    /// <summary>
    /// Virtual method which should be overriden by inherited types that support loading.
    /// </summary>
    /// <param name="row"></param>
    protected virtual void Load(DataRow row)
    {
        throw new NotSupportedException("The object of type '" + this.GetType().Name +
            "' does not support loading from DataRow.");
    }
  • 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-26T17:34:08+00:00Added an answer on May 26, 2026 at 5:34 pm

    Does Customer inherit BusinessObject?

    public class Customer : BusinessObject
    

    And, do you override the method properly (assuming the code for the Load method from this class is is BusinessObject)?

    protected override void Load(DataRow row)
    

    Also, I noticed that the Load method is protected and it looks like you’re calling a public Load method on t. This could cause some confusion as to what methods are actually being called since you can’t override a protected method with a public one (Compiler error: Inconsistent accessibility: base class 'BaseClass.ProtectedMethod' is less accessible than class 'DerivedClass.ProtectedMethod').

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

Sidebar

Related Questions

I have created a Extension method for IQueryable class to convert list of a
I created a class where the main task is get data from the DB
I have a field object and I create a list of fields: class Field
I created drop down list using java. But i am not aware of creating
I've got a static class (DataFormSubject) that holds a generic List object, as follows:
I'm having problems getting the new data from the RandomNumbers List I got this
I have the following method: public IEnumerable<Foo> GetFoo(int x, string y) { return from
I have created a Parcelable object below, my object contains a List of Products.
I have created a simple repository class that is returning a list of Projects:
i'm trying to use the stl map with a class that i've created, from

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.