title: Invalid cast exception - Unable to cast object type 'System.Data.DataRowView' to type 'System.Data.DataRow'
body: <p>I have the following code</p>
  
  <pre><code>public void ConstructUpdateableInventoryItemsOnThisPage(DataView dv)
  {
      //DataRowView dv = null;
      string sTemp = "";
  
      foreach (DataRow dr in dv)
      {
          if (sTemp.Length &gt; 0)
          {
              sTemp += ",";
              sTemp += dr["inventory_id"];
          }
      }
  
      //foreach (DataRow dr in dv)
      //{
      //    if (sTemp.Length &gt; 0)
      //        sTemp += ",";
      //    sTemp += dr.ItemArray[Convert.ToInt32("inventory_id")];  //added ItemArray keyword, square brackets and syntax to convert from string to int 10/21/15 Max //
  
      //}
  
  
  
      mUpdateableInventoryItemsOnThisPage = sTemp;
  
  }
  </code></pre>
  
  <p>And when I go to execute the code I receive the following error:</p>
  
  <blockquote>
    <p>Invalid Cast Exception
        - Unable to cast object type 'System.Data.DataRowView' to type 'System.Data.DataRow'</p>
  </blockquote>
  
  <p>I know that the issue is somewhere in the <code>foreach</code> statement so just in case I included the original code (commented out) and the changes that I made (not commented out).  I am not sure what is causing this could someone point me in the right direction syntactically </p>
  
  <p>Oh by the way this was converted from visual basic if that helps any </p>