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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T14:45:11+00:00 2026-06-11T14:45:11+00:00

I currently have data in db table as follows: Data in table Desc Value

  • 0

I currently have data in db table as follows:

Data in table 
Desc       Value                                                                                                 
BNo        12 
CNo        Null 
ANo        15 
DNo        Null 
ENo        15 

If ANo is blank i need to display BNo. If BNo is blank then display CNo on form. Once i found a non null value based on a defined priority order of DESC(In this case A-E), i need to exit my method. How can this be implemented,i can hard code desc names based on priority but it am looking to implement in a more optimized way. Any advices please.

  • 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-11T14:45:13+00:00Added an answer on June 11, 2026 at 2:45 pm

    It sounds like you have the means to order the list, as you state “in a priority order”. Not sure what this priority is but for the example let’s assume it is in alphabetical order by “Desc”. And let’s also assume (for simplicity) that these values are in a dictionary. Given this you can write a Linq statement as such…

    dict.OrderBy(o => o.Key).FirstOrDefault(d => d != null);
    

    eg…

    Dictionary<string,string> dict = new Dictionary<string,string>();
    dict.Add("BNo", "12");
    dict.Add("CNo", null);
    dict.Add("ANo", null);
    dict.Add("DNo", null);
    dict.Add("ENo", "16");
    
    Debug.WriteLine(dict.OrderBy(o => o.Key).FirstOrDefault(d => d.Value != null));
    

    This will return the first non-null value. If all values are null then null is returned.

    There may be some incorrect assumptions here but the OrderBy and FirstOrDefault should be able to be used in whatever manner necessary to achieve your goal. The only things that should need to change is the “o.Key” and “d.Value” to reference your actual properties.
    For example, if this information is in a class such as this…

    class Info
    {
        public string Desc { get; set; }
        public int? Number { get; set; }
    }
    

    and you have a list of these such as…

    List<Info> info = new List<Info>();
    

    then you could write…

    var returnValue = info.OrderBy(o => o.Desc).FirstOrDefault(d => d.Number.HasValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a table with a current structure as follows: Currently this is populated
I have a database table which currently holds geometric data in SRID 27700 (British
I have a successful query that currently returns all data except for one table.
I currently have the following row in my table: course_data: user_id days <-- This
I have a data Table with numbers formatted according to the current regional settings.
I currently have my data stored in this format : Word1 - Word2 -
I'm coding Settlers of Catan for iOS and currently have my data tiles in
I currently have a app on the market it saves some data with onRetainNonConfigurationInstance
I currently have the following in one solution: Core Project (data access, biz logic,
I currently have this code which stores XML into an XML-type column called data,

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.