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 need to read the editurl from one jqgrid for use in a DND
Actually in one of my project i need to read images from remote server
I need some logic/programming help with reading more than one record from a text
I need to read data from a text file where the field lengths and
I need to copy data from one database to another using a VB.NET program.
I need to read from a file from using C. #include <stdio.h> struct record{
I have a basic/simple need to create a pipeline transfer process from one SQL
I need to read different values stored in a file one by one. So
I really need to use $this->Session->read('id') in one of the model's method therefore I
I need to make a query to one of Google's services. I read this

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.