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

The Archive Base Latest Questions

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

I only use stored procedures to do any operation on the db. I don’t

  • 0

I only use stored procedures to do any operation on the db. I don’t want to use an ORB, before you say that 🙂

For each table I have a corresponding DAO class (VB or C#) for example:

Namespace Dao

    Public Class Client

        Public Sub New(ByVal id As Integer, ByVal description As String)
            Me.id = id
            Me.description = description
        End Sub

        Property id As Integer
        Property description As String
     End Class

End Namespace

The constructor builds the class fields/properties.
In another class I usually build a list (container) of my DAO class, calling a SELECT stored procedure, and getting the fields and building the single DAOs:

Public Shared Function GetList() As List(Of Dao.Client)

    Dim model As New List(Of Dao.Client)

    Using dr As MySqlDataReader = DBUtils.CallReadingStoredProcedure("sp_get_clients")

        While dr.Read
            Dim client As New Dao.Client(dr.GetInt32(0), dr.GetString(1))
            model.Add(client)
        End While

        Return model
    End Using

End Function

Sometimes I need to create the same Dao.class from another method. If the fields to build it are many, it would be useful, instead of directly passing the values to the DAO.class constructor – which is error prone – to just pass the data reader to a different constructor, that extracts the fields and builds itself.

It’s like passing the construction responsibility into the Dao.class itself:

Namespace Dao

    Public Class Client

        Public Sub New(ByVal dr As DataReader)

            Me.id = dr.GetInt32("id")
            Me.marca_id = dr.GetInt32("marca_id")
            Me.categoria_id = dr.GetInt32("categoria_id")
            Me.codice = dr.GetString("codice")
            Me.descrizione = dr.GetString("descrizione")
            ... many other

        End Sub
...
    End Class

End Namespace

This way even if I use different stored procedures to get the Clients, I use the same code to build them.

It works as long as the datareader fields, that is the SELECT fields, are always named the same. This is possible, but when I have a JOIN, the named fields don’t contain the table name, ie with this query in a SP:

SELECT
        OA.id,              -- 0
        OA.articolo_id,         -- 1
        OA.quantita,            -- 2
        OA.quantita_evasa,      -- 3
        OA.prezzo,          -- 4
        A.id,               -- 5
        A.marca_id,         -- 6
        A.categoria_id,         -- 7
        A.codice,           -- 8
        A.descrizione,          -- 9
        A.prezzo_listino,       -- 10
        A.sconto,           -- 11
        A.prezzo_speciale,      -- 12
        A.ha_matricola,         -- 13
        A.unita_misura,         -- 14
        A.peso,             -- 15
        A.codice_barre,         -- 16
        other fields ...
    FROM nm_ordini_articoli OA
    JOIN articoli A ON (OA.articolo_id = A.id)
    other JOINs... 

I can’t do dr.getInt32("OA.id") because the field name is “id” and the table name is “OA”. I could go with indices but this is pure madness, since I should try to use the same indices for the same data in different stored procedures!

Question is: I want a Dao constructor that builds a class giving a datareader; how do I get the named field from a datareader, including the table alias or name? I want to do something like dr.getInt32("real table name", "field name") or dr.getInt32("table.field")

Other advices?
Thanks.

  • 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-20T06:12:01+00:00Added an answer on May 20, 2026 at 6:12 am

    A smart friend of mine gave me this elegant and simple solution: use field aliases…
    It works damn well!

    SELECT
            OA.id AS ordine_articolo_id, 
            ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

By convention our DB only alows the use of stored procedures for INSERT, UPDATE
It is generally accepted that the use of cursors in stored procedures should be
It's my understanding that common wisdom says to only use exceptions for truly exceptional
I'm learning to develop for iPhone (programmatically, I don't like IB). I only use
I heard that static methods should use only static variables in java. But, main
I would like to use a parameter in my mssql stored procedures to switch
I need to use the same Stored Procedures against many tables all with the
Are there any tools that I can use to migrate my Oracle database to
We have a number of stored procedures in production that we would like to
I am trying to use a stored procedure in the entity framework that returns

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.