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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T00:52:01+00:00 2026-05-12T00:52:01+00:00

I have several different lists I want to call. They all have the same

  • 0

I have several different lists I want to call. They all have the same format for the class:
id, value, description, order. Instead of creating a bunch a classes to return the all of the many lists, I wanted to use generics and just TELL it what kind of list to return. However, I can not figure out how to populate the classes.

Here are 2 examples of function in my calling code. This should indicate the type of list and the stored proc used to get the data:

Public Function getTheEyeColors()
    Dim glEyeColors As New GenericList
    Return glEyeColors.GetALList(Of EyeColor)("GetAllEyeColors")
End Function

Public Function getTheHairColors()
    Dim glHairColors As New GenericList
    glHairColors.GetALList(Of HairColor)("GetAllHairColors")
End Function

And here is the code I am trying to use to build the generic list…

Public Function GetALList(Of t)(ByVal storedproc As String) As List(Of t)

    Dim lstGenericList As New List(Of t)
    Dim oGenericListItem As t
    Dim oProviderFactory As New ProviderFactory
    Dim oConnection As DbConnection
    Dim oReader As System.Data.IDataReader
    Dim oFactory As DbProviderFactory
    Dim oFileMgt As New FileMgt
    Dim oCmd As DbCommand

    oFactory = oProviderFactory.GetFactory
    oConnection = oProviderFactory.GetProviderConnection(oFactory)
    oCmd = oConnection.CreateCommand
    oCmd.CommandType = CommandType.StoredProcedure

    oCmd.CommandText = storedproc

    Using (oConnection)

        oConnection.Open()
        oReader = oCmd.ExecuteReader()

        While oReader.Read
            HERE IS WHERE I AM NOT SURE HOW TO POPULATE THE EYECOLOR OR HAIRCOLOR CLASS
            lstGenericList.Add(oGenericListItem)
        End While

        oConnection.Close()

    End Using

    Return lstGenericList

End Function
  • 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-12T00:52:02+00:00Added an answer on May 12, 2026 at 12:52 am

    You could add two generic constraints; I don’t know how to express them in VB, but here’s the C# version:

    • T : new() – there has to be a parameterless constructor
    • T : ICommonInterface – T has to implement an interface

    You then put the common properties (ID, Value, Description, Order) into the interface, and you’ll be able to create a new T(), set the properties and add it to the list.

    EDIT:

    The VB Syntax to specify that it must both be creatable and implement an interface is:

    • (Of T As {ICommonInterface, New})
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a large class, which I have divided into several different class extension
I have a SalesOrder class which is inherited by several different types of sales
I have an object in a list that I need to rank several different
I have several different content type nodes (videos, image galleries, stories...) that I would
I have several sites in different domains: example.com , example.org , mail.example.com and passport.example.org
In our infrastructure we have several nodes with different capabilities (in terms of services).
I have several entities which respresent different types of users who need to be
I have an app with several different tabs. The first of these tabs should
I have several similar user controls which display listviews of respectively different data entities.
I have a .NET application available in several different language. i basically load and

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.