title: How to retrieve data from database in label
body: <p>I wanat to retrieve student ID from database. Here is my code what i have tried but it is not displaying anything.
  Thanks...</p>
  
  <pre><code>protected void Button2_Click(object sender, EventArgs e)
  {
  
          SqlConnection con = new SqlConnection("Data Source=DESKTOP-Q69PRF4;Initial Catalog=new;Integrated Security=True");
  
  
          if (con.State == ConnectionState.Open)
          {
              con.Close();
          }
          con.Open();
          string str = "select * from StRecords where StID='" + Session["login"] + "'";
          SqlCommand com = new SqlCommand(str, con);
          SqlDataAdapter da = new SqlDataAdapter(com);
          DataSet ds = new DataSet();
      DataTable dt = new DataTable();
          da.Fill(dt);
      if (dt.Rows.Count &gt; 0)
      {
          Label11.Text = dt.Rows[0]["StID"].ToString();
  
      }
  
  
      }
  </code></pre>