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();
If you are expecting one product from your database you can change the
whiletoifBut I think ProductID should be unique