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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T05:08:32+00:00 2026-06-07T05:08:32+00:00

I want to set value to a literal control using LINQ. I got the

  • 0

I want to set value to a literal control using LINQ. I got the result from database in var by the following code:

var result=md.StoredProc_Name(id);

Now I want to assign particular columns value to a literal. As we can do simply in asp.net as bellow with the help of datatable,

dt=obj.Test(id);
ltrlName.Text=dt.Rows[0]["Name"].ToString();
ltrlAddress.Text=dt.Rows[0]["Address"].ToString();

How can we do the same thing in LINQ?

  • 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-07T05:08:34+00:00Added an answer on June 7, 2026 at 5:08 am
    var first = result.FirstOrDefault();
    
    if (first != null)
    {
       ltrlName.Text = first.Name;
       ltrlAddress.Text = first.Address;
    }
    

    Addendum – How to do this without linq to objects:

    With the code below in a class called DB

    var result = DB.SelectIntoItem("StoredProc_Name",
                                   connectionString,
                                   System.Data.CommandType.StoredProcedure,
                                   new { param1 = "val1" });
    
    if (!reader.Empty)
    {
       ltrlName.Text=result.Name;
       ltrlAddress.Text=result.Address;
    }
    etc.
    

    Code

    public static dynamic SelectIntoItem(string SQLselect, string connectionString, CommandType cType = CommandType.Text, object parms = null)
    {
      using (SqlConnection conn = new SqlConnection(connectionString))
      {
        using (SqlCommand cmd = conn.CreateCommand())
        {
          dynamic result = new System.Dynamic.ExpandoObject();
    
          cmd.CommandType = cType;
          cmd.CommandText = SQLselect;
    
          if (parms != null)
            Addparms(cmd, parms);
    
          conn.Open();
    
    
          using (SqlDataReader reader = cmd.ExecuteReader())
          {
            if (reader.Read())  // read the first one to get the columns collection
            {
              var cols = reader.GetSchemaTable()
                           .Rows
                           .OfType<DataRow>()
                           .Select(r => r["ColumnName"]);
    
              foreach (string col in cols)
              {
                ((IDictionary<System.String, System.Object>)result)[col] = reader[col];
              }
              result.Empty = false;
    
              if (reader.Read())
              {
                // error, what to do?
                result.Error = true;
                result.ErrorMessage = "More than one row in result set.";
              }
              else
              {
                result.Error = false;
              }
    
            }
            else
            {
              result.Empty = true;
              result.Error = false;
            }
          }
    
          conn.Close();
    
          return result;
        }
      }
    }
    
    private static void Addparms(SqlCommand cmd, object parms)
    {
      // parameter objects take the form new { propname : "value", ... } 
      foreach (PropertyInfo prop in parms.GetType().GetProperties())
      {
        cmd.Parameters.AddWithValue("@" + prop.Name, prop.GetValue(parms, null));
      }
    }
    

    If you are insterested follow my GitHub, I’ll be making the rest of it public soon (GitHub)

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

Sidebar

Related Questions

i want to set the value to a insert query from select query ,how
I want to set an HTML field's value using JavaScript when onclick event is
I want to set the value of a hidden field, using JQuery. Hidden Field:
in my application I want set textfield value dynamically coming from header. Here is
I want to set the value of Inclusion list for Moderate risk file Types
I have a datagrid and I want to set the value of a dropdownlist
Given a certain date, I want to set the value of a cell with
I have a PowerShell module called Test.psm1. I want to set a value on
i want to set the default value in a sql server 2005 datetime field
I want to set the endpoint specific header value in Multicast component. XML DSL

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.