title: Using while loop for sqldatareader
body: <p>I trying to get both <strong>policeid</strong> and <strong>fullname</strong> from my table named <strong>PoliceAccount</strong> when the <strong>handle</strong> column equal to the value of the dropdownlist and then put the value into a label and display it. By using the code provided below I keep getting the result of the last row data of <strong>policeid</strong> and <strong>fullname</strong>. However, my table contain of 2 police account which having the column <strong>handle</strong> equal to the value of the dropdownlist. Do help me out. THANKS!</p>
  
  <pre><code>conn.Open();
  sql = "Select policeid, fullname From PoliceAccount Where handle = '"+ ddlReportDateTime.SelectedValue +"'";
      using (var cmd2 = new SqlCommand(sql, conn))
      {
          SqlDataReader dr;
          dr = cmd2.ExecuteReader();
  
          while (dr.Read())
          {
              String policeid = dr.GetString(0);
              String fullname = dr.GetString(1);
              String result = policeid + " " + fullname;
              lblAssignTo.Text = result;
          }
      }
  conn.Close();
  </code></pre>