title: C# Windows Forms Application - display sql server values in textbox
body: <p>I need assistance to display sql server values in a windows forms. In the application below if the query returns a row then the values are displayed. I understand that I am to use sqldatareader but so far I have been unsuccessful how to add it. </p>
  
  <pre><code>SqlConnection ChuoDB_Connection = new SqlConnection("Data Source=test-PC\\tester;Initial Catalog=Chuo;Integrated Security=True;Pooling=False");
  
      SqlDataAdapter select_adapt;
  
  private void btn_guardian_student_search_Click(object sender, EventArgs e)
      {
          if (rd_btn_guardian_student_no.Checked == true)
  
          {
              DataSet ds = new DataSet();
              SqlDataReader dr;
              ChuoDB_Connection.Open();
  select_adapt = new SqlDataAdapter("SELECT * FROM Guardian WHERE STUDENT_NO = @student_no", ChuoDB_Connection);
  
  select_adapt.SelectCommand.Parameters.Add("@student_no", SqlDbType.Int).Value = Convert.ToInt32(txt_bx_guardian_student_search.Text);
  
              select_adapt.Fill(ds);
  
              if (ds.Tables[0].Rows.Count == 0)
              {
                  lbl_guardian_student_search.Text = "No Guardian record exists for this student. Please enter the Guardian Information";
                  ChuoDB_Connection.Close();
  
              }
  
              if (ds.Tables[0].Rows.Count &gt; 0)
              {
                  lbl_guardian_student_search.Text = "";       
  
                while (dr.read())
                  {
                      txtBox1.Text = rdr.Item["DBFieldName1"].ToString();
                      txtBox2.Text = rdr.Item["DBFieldName2"].ToString();
                  }
  
  
  
              }                
  
  
          }
      }
  </code></pre>