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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:03:55+00:00 2026-06-13T23:03:55+00:00

how can I pass value from selected field (LINQ) to textbox in winforms? If

  • 0

how can I pass value from selected field (LINQ) to textbox in winforms?

If single fields, I just do like this

   var result = from row in dtValueBranch.AsEnumerable()
                         where row.Field<int>("branchID") == idBranch
                         select row.Field<string>("branchName");

        StringBuilder sb = new StringBuilder();

        foreach (string s in result)
        {
            sb.Append(s + Environment.NewLine);
        }

        tbBranch.Text = sb.ToString();

So this is the code LINQ to many fields

    var result = from row in dtValueBranch.AsEnumerable()
                 where row.Field<int>("branchID") == idBranch
                 select new
                 {
                      BranchName = row["branchName"].ToString(),
                      branchTel = row["branchTel1"].ToString(),
                      // And many more fields

                 };

How can I to implement each fields to each textbox?

  • 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-13T23:03:56+00:00Added an answer on June 13, 2026 at 11:03 pm

    Keeping in mind that your result query may have multiple rows, your question appears to be focused on how to access the fields of one row. You can do that like this:

    var row = result.First();  // select first row of results
    
    textbox1.Value = row.BranchName;
    textbox2.Value = row.branchTel;
    // etc..
    

    The select new syntax in your query creates an anonymous type in the result enumeration. You can’t refer to that type by name, but you can create local variables (like row) if you use the var declaration style and let the compiler do type inferencing.

    If you want to cram all the values of one field across all rows into into one textbox (as in your first code sample), you can do something like this:

        StringBuilder sbBranch = new StringBuilder();
        StringBuilder sbBranchTel = new StringBuilder();
        // etc
    
        foreach (var row in result)
        {
            sbBranch.Append(row.BranchName);
            sbBranch.Append(Environment.NewLine);
            sbBranchTel.Append(row.branchTel);
            sbBranchTel.Append(Environment.NewLine);
            // etc
        }
    
        tbBranch.Text = sbBranch.ToString();
        tbBranchTel.Text = sbBranchTel.ToString();
        // etc
    

    However, if you’re wanting to display multiple rows of multiple fields of data, you might want to look at using a data grid control instead of a herd of textboxes. You’ll save yourself a lot of effort, and your users will probably thank you too.

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

Sidebar

Related Questions

How can I pass the result from a scalar [single row, single value] query
Can I pass value to Navigation Context like this: NavigationContext.QueryString[param1] = PARAM1; Is it
I would like to retrieve selected value from dropdown and pass it using Yii's
How can I pass a variable value from a template using JavaScript without using
I'm generating a string of values (colors) like so: 'red|green|blue|yellow|orange|black' Can I pass this
Hi guys i have to pass the checked value from checkbox and selected value
How can i pass value from grid view to a pop up in client
Can I pass a value out of a javascript function and back to the
How can I pass an object of a MyClass (C#) by Parameter-by-Value to a
Hi can some one point me some guidance, i pretend to pass the value

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.