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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T19:14:34+00:00 2026-05-12T19:14:34+00:00

I have 3 database tables, all of them have the same 5 columns. They

  • 0

I have 3 database tables, all of them have the same 5 columns.
They differ in that table#2 and table#3 each have another ID column in them.

I don’t want to create 3 seperate classes for this, but the problem is in my database helper class I have a method that loads the classes, like:

public static LoadClass1(SqlDataReader reader)
{
     Class1 c1 = new Class1();

     c1.prop1 = (int)reader["prop1"]

}

I don’t want to have to create 3 seperate load helper methods, and have to copy the code over on all of them. (I don’t mind creating 3, but only having to set the fields that are different in each one).

  • 1 1 Answer
  • 1 View
  • 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-12T19:14:34+00:00Added an answer on May 12, 2026 at 7:14 pm

    Four methods: one that loads the core fields, three others that call the core method and load the extra fields. This would work best with a base class with the core properties, and 3 subclasses.

    //Psuedo code, obviously not exact
    //Don't hate
    public abstract class Core
    {
        int field1;
        int field2;
        int field3;
        int field4;
        int field5;
    }
    
    public class Sub1 : Core 
    {
        field 6;
    }
    
    ...
    
    public static void LoadCore(Core c, DataTable dt)
    {
        c.field1 = dt.getField1(); //Really a database value
        c.field2 = dt.getField2();
        c.field3 = dt.getField3();
        c.field4 = dt.getField4();
        c.field5 = dt.getField5();
    }
    
    public static Sub1 LoadSub1()
    {
        Sub1 s = new Sub1();
        LoadCore(s, MY_DATA_TABLE);
        s.field6 = MY_DATA_TABLE.getField6();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All tables in my database always have an id (autoincrement), at column 0 regardless
I have a java class containing all the columns of a database table as
I have several database tables that just contain a single column and very few
I have a database two tables and a linking table that I need a
I have a 5GB database, all tables are MyISAM. It runs into heavy load
I have a table in an Access 2007 database. All fields are of type
I have a PostgreSQL database with two tables named user and group. They have
Consider we have a database that has a table, which is a record of
I have two tables in a database. Table 1 includes an order number which
I'm using rails 3. In my database I have several tables that work together

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.