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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:47:39+00:00 2026-05-27T03:47:39+00:00

Sometimes there is situations where I need to take a value from a database

  • 0

Sometimes there is situations where I need to take a value from a database lookup table similar to:

Id | Description
----------------
1  | descriptive text for 1
2  | descriptive text for 2

The Id vlaue is often stored in a variable:

private int DB_LookUp_Id = GetIdFromDB();

This DB_LookUp_Id value is then used to perform validation or other business logic like:

if (DB_LookUp_Id == 1)
    return true

This code will break if the Id value changes from, say 1 to 3

What is a good way to eliminate this problem?

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-27T03:47:39+00:00Added an answer on May 27, 2026 at 3:47 am

    Have a code-based key alongside the database ID that is static, we tend to use either Guids or enumerated values for this:

    Id | Key | Description
    ----------------
    1  | 1   | descriptive text for 1
    2  | 2   | descriptive text for 2
    

    Then in code you could have:

    enum DescriptiveTextParts
    {
        Part1 = 1,
        Part2 = 2,
    }
    
    if (DB_LookUp_Key == DescriptiveTextParts.Part1)
        return true;
    

    Not sure if this is “best practice”, but it works for us. Database primary keys do not always need to be known or used by the application, though most of the time they are.

    Alternatively, if it’s all just text, ship it all into a resource file. This gives you localisation, compile-time benefits, and performance benefits. To the detriment of database access to resource strings (pretty much no access), and ability to release new strings without re-compilation.

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

Sidebar

Related Questions

my Page has many hover images, sometimes there are backgrounds from div-elements or src
I have a situation where I need to generate a table from a stored
I need to read the response from an HTTP GET in situations where the
I program in C++. Sometimes there are 1000 ways to do something, and depending
I have a div with a set height of 200, and sometimes there's enough
I have a really cool website that allows people to upload images. Sometimes there
I have a column called post_tags where there is sometimes one tag entry and
Having friendly URLs is generally a good thing. However, there are sometimes when it
Is there a difference between NULL and null in PHP? Sometimes they seem to
Are there any tools for just browsing SQL Server? I ask because sometimes SSMS

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.