title: Checking if a table contains a Row C#
body: <p>I'm trying to figure out if my data table contains a certain row. So I used the .Contains method, but when I tried to run my program I was met with a MissingPrimaryKeyException which I can't figure out.</p>
  
  <pre><code>DataTable table = dataQuery.executeQuery();
  
  foreach(DataRow row in table.Rows)
  {
      if(table.Rows.Contains("certainRow"))
      {
          blah blah blah
      ...
  </code></pre>
  
  <p>I am only getting the exception the 2nd time I call table.Rows which is what is making no sense to me. If my table didn't have a primary key, wouldn't it have given me an error in the foreach call?</p>
  
  <p>EDIT: I just realized that Contains did something else than I thought it did. Matthijs... yes that is kind of what I want. I need to know if "certainRow" is actually a row that exists otherwise I cannot manipulate the data in that row. </p>
  
  <p>Unfortunately I am new to C# and haven't programmed in anything in over 5years so I cannot figure out if there is a method that does what I want. Or if I need to create something myself.</p>
  
  <p>EDIT#2:
  I figured out a solution to my problem using the DataTableReader.</p>
  
  <pre><code>private bool doesExist(string rowName, DataTable table)
      {
          bool value = false;
          DataTableReader reader = new DataTableReader(table);
  
          while (reader.Read())
          {
              for (int i = 0; i &lt; reader.FieldCount; i++)
              {
                  if (reader.GetValue(i) == rowName)
                  {
                      value = true;
                  }
              }
          }
          return value;
      }
  </code></pre>