title: Get Values from DataTable by row and column name
body: <p>I'm typically used to traditional table in <code>SQL</code> where I have multiple <code>columns</code> with rows populated. I execute a stored procedure and store all the data in <code>DataTable</code> and loop through the table to get the results I need. For example,</p>
  
  <pre><code> public static DataTable getInfo (string sessionID)
      {
          try
          {
              SqlConnection conn = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["SandBox"].ConnectionString);
              SqlCommand cmd = new SqlCommand("GetSessionInfo", conn);
              cmd.Parameters.AddWithValue("SessionGUID", sessionID);
              cmd.CommandType = CommandType.StoredProcedure;
              DataTable dt = new DataTable();
              SqlDataAdapter da = new SqlDataAdapter(cmd);
              da.Fill(dt);
              return dt;
          }
          catch (Exception)
          {
  
              throw;
          }
      }
  </code></pre>
  
  <p>I would load the DataTable:</p>
  
  <pre><code> DataTable infoTbl = new DataTable();
   infoTbl = getInfo(lbldatabasesessionID.Text);
  </code></pre>
  
  <p>And I would use <code>foreach</code> loop to loop through the DataTable.</p>
  
  <pre><code>foreach (DataRow row in infoTbl.Rows)
  {
     string x = col.ToString();
  }
  </code></pre>
  
  <p>The issue I run into is the database guy gave me a stored procedure that returns a different output <em>(different from what I'm used to)</em>. It's a row based.</p>
  
  <p><img src="https://i.stack.imgur.com/Bfi3W.png" alt="enter image description here"></p>
  
  <p>The only way I can access for example the <code>First Name</code> is if I hard code the position like:</p>
  
  <pre><code>string firstName = infoTbl.Rows[16][2].ToString();
  </code></pre>
  
  <p>I don't feel comfortable doing this since the position could potentially change. How would I access <code>ElementValue</code> by knowing the name knowing <code>ElementType</code> and <code>ElementName</code>?</p>
  
  <p>Any suggestions?</p>