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

  • Home
  • SEARCH
  • 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 7792649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T22:15:00+00:00 2026-06-01T22:15:00+00:00

May I ask someone to help me write this in LINQ, DataTable dt =

  • 0

May I ask someone to help me write this in LINQ,

 DataTable dt = new DataTable();

            DataColumn dcValue = new DataColumn();
            dcValue.ColumnName = "value";

            DataColumn dvDisplay = new DataColumn();
            dvDisplay.ColumnName = "display";

            DataColumn dvIsDefualt = new DataColumn();
            dvIsDefualt.ColumnName = "isDefalt";

            dt.Columns.Add(dcValue,int);
            dt.Columns.Add(dvDisplay,string);
            dt.Columns.Add(dvIsDefualt,bool);

            this.tipRacuna.DataSource = ds.Tables[0];
            this.tipRacuna.ValueMember = "value";
            this.tipRacuna.DisplayMember = "display";

            this.tipRacuna.SelectedValue =  findDefault(dt);//linq to find first value with default = true;    


        }
        private int findDefault(DataTable dtt)
            {
                int i= 0;

            foreach (DataRow  dr in dtt.Rows)
            {
                if (bool.Parse(dr["isDefalt"].ToString()))
                {
                    return int.Parse(dr["value"].ToString());
                }
            }
                return i;
            }

As I am getting more involved in C# and programming at all, I am getting more intersting in LINQ queries.
In begins I always skip LINQ taking argument as I know TSQL no needs for another Query language, but when I see how many lines of code i can save using LINQ i start learning it.

  • 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-01T22:15:02+00:00Added an answer on June 1, 2026 at 10:15 pm

    Assuming that your DB columns are strongly-typed (best):

    dtt.AsEnumerable().Where( dr => dr.Field<bool>("isDefault" ) )
        .Select( dr => dr.Field<int>( "value" ) ).FirstOrDefault();
    

    With type conversion:

    dtt.AsEnumerable().Where( dr => Convert.ToBoolean( dr["isDefault"] ) )
        .Select( dr => Convert.ToInt32( dr["value"] ) ).FirstOrDefault();
    

    With parsing:

    dtt.AsEnumerable().Where( dr => bool.Parse( dr["isDefault"].ToString() ) )
        .Select( dr => int.Parse( dr["value"].ToString() ) ).FirstOrDefault();
    

    Note that I have corrected the spelling of “isDefalt” to “isDefault”.

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

Sidebar

Related Questions

There may be more than one way to ask this question, so here's a
This may be a stupid question to ask, but still I need to know
This may be rather noobish but I'm gonna ask anyhow. I have a class
This may not be the kind of question one should ask on StackOverflow, but
This may sound like a bit of a rhetorical question, but I ask it
This may not be a programming question, but I don't know where to ask
This may be a stupid question, but I have to ask! I have the
I'm not a DBA so this may be a stupid question but I'll ask
this my first question on here. I hope someone can help. It is to
I realize this may be subjective, so will ask a concrete question, but first,

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.