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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T12:51:55+00:00 2026-06-08T12:51:55+00:00

I am retrieving one of my column table’s values and store it in a

  • 0

I am retrieving one of my column table’s values and store it in a Label. After storing it in a Label, I will session the Label over to another page. However, the values i am retrieving must be according to what the user click. For example, User click the 2nd product in my webpage. So the name of the second product have to be session over to the next page.

My problem here is that I managed to retrieve the values but it is not according to what the user click. The output of my Label came out to be all the product name which is not i want it to be. Where have i gone wrong?

Here is my .cs code:

string strConnectionString = ConfigurationManager.ConnectionStrings["PRODUCTSConnectionString"].ConnectionString;


    SqlConnection myConnect = new SqlConnection(strConnectionString);

    string strCommandText = "SELECT productName from Products";
    SqlCommand cmd = new SqlCommand(strCommandText, myConnect);

    myConnect.Open();
    SqlDataReader reader = cmd.ExecuteReader();

    Label1.Text = "";

    while (reader.Read())
    {
        Label1.Text += reader["productName"].ToString() + "<br/>";
    }

    reader.Close();
    myConnect.Close();
  • 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-08T12:51:56+00:00Added an answer on June 8, 2026 at 12:51 pm

    If you are expecting one product from your database you can change the while to if

    string strCommandText = "SELECT productName from Products WHERE productID=@ProductID";
    SqlCommand cmd = new SqlCommand(strCommandText, myConnect);
    cmd.Parameters.AddWithValues("@ProductID", productID);
    ...
    
    if(reader.Read())
    {
      //Label1.Text += reader["productName"].ToString();
      Label1.Text = reader["productName"].ToString();
    }
    

    But I think ProductID should be unique

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

Sidebar

Related Questions

When retrieving a hierarchical structure from MySQL (table with one ID column and one
I'm trying to autocomplete a textbox. I'm retrieving values from Access Database. Just one
I've got a .php page showing a HTML table similar to this one :-
I'm retrieving data from a table through VBA.The select query gives output correctly.One of
I am retrieving one query string parameter, and for that my code is <a
One of my friend has been asked with a question Retrieving the max top
I have used a join query for retrieving value from two tables one is
I'm retrieving data from a MySQL table and displaying it on a webpage using
I am retrieving an array values from database which save multi dimensional array..i want
Could someone tell me how can I assign 2 column values to the JComboBox

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.