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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T12:18:43+00:00 2026-05-13T12:18:43+00:00

I need to read one record from a database (determined by the url’s querystring),

  • 0

I need to read one record from a database (determined by the url’s querystring), and take one field from it (“Cost”). The SQL currently in my datasource for it is just:

SELECT [Cost] from [Cars] WHERE ([RegistrationNumber] = @RegistrationNumber)

…then @RegistrationNumber is defined as coming from the QueryString.

I’m very much still learning ASP.NET, so it is likely (I’m hoping) that there’s a very simple way to do this. I could use a ListView or something, but I think that’s a bit overkill for just one piece of data.

Also, I’m working in C# if that makes a difference.

  • 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-13T12:18:44+00:00Added an answer on May 13, 2026 at 12:18 pm

    Assuming you’re using a SqlCommand object to execute your sql, you can use the ExecuteScalar() method, and it will return the first value from the first row that is returned from the command.

    There is an example on the documentation page I linked, but for brevity, I’ll include it here:

    using (SqlConnection conn = new SqlConnection(connString))
        {
            SqlCommand cmd = new SqlCommand(sql, conn);
            cmd.Parameters.Add("@RegistrationNumber", SqlDbType.VarChar);
            cmd.Parameters["@RegistrationNumber"].Value = ** your variable here**;
            try
            {
                conn.Open();
                double cost = (double)cmd.ExecuteScalar();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }
        }
    

    That’s the “raw” method of running your SQL. Since you’re using a SqlDataSource, that’s what it’s doing behind the scenes, except it’s not using ExecuteScalar() – it’s just getting all the data. You can pick out individual fields using code similar to this:

    protected void Page_Load(object sender, EventArgs e)
    {
    
        DataView dv= (DataView)SqlDataSource1.Select(DataSourceSelectArguments.Empty);
        foreach (DataRowView dr in dv)
        {
            Label1.Text = dr["Cost"].ToString();
        }
    }
    

    This would assign the field value to Label1. If you don’t want to have to write any code, it might be easier just to bind it to a simple Repeater control though.

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

Sidebar

Related Questions

I read books, articles, tutorials, and all that kind of stuff about the n-tier
One of our sites has around 10,000 nodes. In each node, there is a
I'm trying to set up a program to record a portion of an internet
http://en.wikipedia.org/wiki/Upsert Insert Update stored proc on SQL Server Is there some clever way to
This is a long question that I do not know how to summarize... I
I've seen various MVC frameworks as well as standalone ORM frameworks for PHP, as
I have an activity for initialising a game, that does multiple selects and inserts
I'm working on a social network, like a subset of Facebook. I think this
I have been trying to understand the MapReduce concept and apply it to my
Is there any PHP PDF library that can replace placeholder variables in an existing

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.