title: Get value from dataset cell
body: <p>I am trying to get the value of a specific cell in a dataset. I have a dataset that has at least two tables(could be more). One of the tables has two columns - Name$ and Value$. </p>
  
  <p>I have to search through the dataset by the name column where the name is "FirstName" and save the value corresponding to that specific name. </p>
  
  <p>Here is what I have so far:</p>
  
  <pre><code>string val = null;
  foreach (DataTable dt in ds.Tables)
  {
      foreach (DataRow dr in dt.Rows)
      {
          foreach (DataColumn dc in dt.Columns)
          {
              object item = dr[dc];
  
              if (item.ToString().Equals("Name$"))
              {
                  // store the value for that name
              }
          }
      }
  }
  </code></pre>
  
  <p>Any ideas how this could happen, keeping in mind that there could be many tables in the dataset.</p>
  
  <p>EDIT: Here is the full solution:</p>
  
  <pre><code>foreach (DataTable dt in ds.Tables)
          {
              foreach (DataRow row in dt.Rows)
              {
                  foreach (DataColumn dc in dt.Columns)
                  {
                      if (dc.ColumnName.ToString().Equals("Name$"))
                      {
                          if (row["Name$"].ToString().Equals("FirstName"))
                          {
                              firstName = (string)row[row.Table.Columns["Name$"].Ordinal + 1];
                          }
  
                          if (row["Name$"].ToString().Equals("LastName$"))
                          {
                              lastName = (string)row[row.Table.Columns["Name$"].Ordinal + 1];
                          }
                      }
                  }
              }
          }
  </code></pre>