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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T06:17:44+00:00 2026-05-18T06:17:44+00:00

I am using c# and SQL Server to get data from the database and

  • 0

I am using c# and SQL Server to get data from the database and populate a few labels on a page on pageload. The information comes from a SQL view which returns a whole bunch of information in a single row. eg:

SELECT 'car' AS product, 12 As daysUntilEOM, '2010-01-01' AS LastHoliday, 23.7 AS Length

There will always be only 1 row returned

The rest of my project is using LINQ and I originally started going down that path, but what is the point of creating an object that I’m only going to use once off for this, assigning all the values into the object as key-value pairs, and then reassigning them out to the label texts? Seems a lot of pointless coding.

Using a datareader also seems to have the same problem.

The simplest solution (ie least code) I can see is to use a dataAdapter to fill a dataset and pass the dataset back from the DAL to the page and then do the assigning straight to the labels. But for a single row of data this seems to be like using a truck to carry a single tomato.

Is there something like ExecuteScalar that returns a whole row instead of just the first column?
Or should the ease of coding the DataAdapter just be enough and I should stop worrying about overhead?

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-18T06:17:45+00:00Added an answer on May 18, 2026 at 6:17 am

    You should call ExecuteReader and pass the CommandBehavior.SingleRow flag.

    To avoid coupling, you can convert the DataReader into a dictionary, like this:

    return Enumerable.Range(0, reader.FieldCount)
                     .ToDictionary(reader.GetName, reader.GetValue);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is it possible to get notifications using SQL Server Reporting Services ? Say for
I'm using SQL Server 2005 and would like to know how I can get
Using sql server 2000, I would like to take my production data and put
When using SQL Server Management Studio from SQL Server 2005, I can connect to
I'm using SQL Server 2000 to print out some values from a table using
Using SQL Server, how do I split a string so I can access item
Using SQL Server, which is the fastest or best practice method to use for
Using SQL Server 2005 and Management Studio how do I insert a picture into
I am using SQL Server 2005. I have a table with a text column
I'm using SQL Server 2005, and I would like to know how to access

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.