title: C# Asp.net Webforms simple SQL Query for 1 row several columns to variables
body: <p>I have been searching around and I am either confusing myself or not searching for the right thing.</p>
  
  <p>I have this data reader that pulls some information for a store procedure.. but I don't think I am doing it right.</p>
  
  <pre><code>string constr = ConfigurationManager.ConnectionStrings["PAYROLL"].ConnectionString;
  
  using (SqlConnection con = new SqlConnection(constr))
  {
      using (SqlCommand cmd = new SqlCommand("DLI_EMPLOYEE_PORTAL_EMPLOYEE_INFORMATION"))
      {
          cmd.CommandType = CommandType.StoredProcedure;
          cmd.Parameters.AddWithValue("@EID", Session["sessionEMPID"].ToString());
          cmd.Connection = con;
  
          con.Open();
          SqlDataReader dataReader = cmd.ExecuteReader(CommandBehavior.CloseConnection);
  
          while (dataReader.Read())
          {
              string EMP_FIRST = dataReader["FIRST_NAME"].ToString();
              string EMP_LAST = dataReader["LAST_NAME"].ToString();
              string EMP_DEPT = dataReader["DEPT"].ToString();
              string EMP_DEPT_ID = dataReader["DEPT_ID"].ToString();
  
              body = body + "&lt;p&gt;SUBMITTED BY : (" + Session["sessionEMPID"].ToString() + ") " + EMP_FIRST + " " + EMP_LAST + " - DEPT : " + EMP_DEPT + "&lt;/p&gt; " + System.Environment.NewLine;
          }
  
          con.Close();
      }
  }
  </code></pre>
  
  <p>I just need to query one row based of an employee ID.. and I would rather do it not by stored procedure but a select query.</p>
  
  <pre><code>SELECT e.FIRST_NAME, e.LAST_NAME, e.DEPT_ID, d.NAME 
  FROM EMPLOYEE AS e 
  INNER JOIN DEPARTMENT AS d ON e.DEPT_ID = d.ID 
  WHERE (e.ID = 'sim01')
  </code></pre>
  
  <p>I am building an HTML body string so that is why I need the information.</p>
  
  <pre><code>body = body + "&lt;p&gt;SUBMITTED BY : (" + Session["sessionEMPID"].ToString() + ") " + EMP_FIRST + " " + EMP_LAST + " - DEPT : " + EMP_DEPT + "&lt;/p&gt; " + System.Environment.NewLine;
  </code></pre>
  
  <p>Any help is greatly appreciated.  Thank you.</p>