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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T06:30:33+00:00 2026-06-09T06:30:33+00:00

I’m building a MVC structure for a part of my program. I’ve done the

  • 0

I’m building a MVC structure for a part of my program.

I’ve done the Models of 5-10 tables and what they have in common is only the constructor. (which takes the recordset.fields)

Here’s my function to fill these objects:

Public Function reqTable(ByVal pTable As String, ByVal pType As Type, ByVal pNoProjet As Integer, Optional ByVal strAdditionnalConditions As String = "") As List(Of Object)
    Dim lstRetour As List(Of Object) = New List(Of Object)

    rsRequestCSV = conSQL.Execute("SELECT * FROM " & pTable & " WHERE NoProjet = " & pNoProjet & " " & strAdditionnalConditions)
    With rsRequestCSV
        While Not .EOF
            lstRetour.Add(Activator.CreateInstance(pType, New Object() {rsRequestCSV.Fields})) 'New clsTable(rsRequestCSV.Fields))
            .MoveNext()
        End While
    End With
    Return lstRetour
End Function

What I’m not able to achieve is to return a List(Of pType) instead of List(Of Object).

The reason I want this is to have headers in my datagridviews even if they’re empty.

So is there a way to return a List(Of MyModel’sType) ?

thanks in advance!

  • 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-09T06:30:34+00:00Added an answer on June 9, 2026 at 6:30 am

    Just use As pType instead of As Object (but consider using a conventional type argument name, i.e. T instead of pType), remove the now obsolete pType argument, and use the following to create and add the instances:

    Public Function ReqTable(Of T)(ByVal table As String, ByVal noProject As Integer, Optional ByVal additionalConditions As String = "") As List(Of T)
        Dim result As New List(Of T)()
    
        ' Where is this declared?! It probably should be declared here.
        request = conSQL.Execute( _
            String.Format("SELECT * FROM {0} WHERE NoProjet = {1} {2}", _
                          table, noProjet, additionnalConditions))
    
        While Not request.EOF
            result.Add( _
                CType(Activator.CreateInstance( _
                        GetType(T), New Object() {request.Fields}), _
                    T))
            request.MoveNext()
        End While
    
        Return result
    End Function
    

    GetTpe(T) gets you a System.Type instance representing the type argument. Since VB, unlike Java, has reified generic types you can thus create instances from type argument.

    Apart from that, pay attention that .NET has different code style conventions than Java; for instance, all methods should use PascalCase, not camelCase. And like in Java, use of Hungarian notation is discouraged. Use concise but descriptive names. And, as Rene noted, your code suffers from an SQL injection vulnerability.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have an autohotkey script which looks up a word in a bilingual dictionary
I have a text area in my form which accepts all possible characters from
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I am trying to understand how to use SyndicationItem to display feed which is
I used javascript for loading a picture on my website depending on which small
I have a jquery bug and I've been looking for hours now, I can't

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.