How to access DataRow.rowID?

    General discussion

  • Hi,
    How can I access DataRow.rowID? I see it in the variable window during debugging, but I'm not allowed to access it in my program. Is there any possibility to know the row ID of a given row in its table, without enumerationg through all?
    Thanks, Rainer.
    Wednesday, December 31, 2003 6:36 AM

All replies

  • You probably resolved this long ago, but thought I'd post a resolution for others, there are better ways to do this, but this quick hack works

    foreach(DataRow dataRow in foundRows)
    System.Reflection.FieldInfo fieldInfo = dataRow.GetType().GetField("rowID",System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance); 
    int rowID = (int)fieldInfo.GetValue(dataRow);

    Thursday, September 02, 2004 12:22 PM
  • Absolutely fantastic !
    I've been trying to crack that one for ages.  Not being able to access DataRow.rowID was a real pain.

    Thanks for this great solution.

    Big Smile

    Thursday, July 14, 2005 1:54 PM
  • I'm clearly doing something wrong in the following because for some reason fieldInfo is always null:

    foreach (DataRow dataRow in items.Tables[0].Rows)


    if (((DateTime)dataRow["due_date"]) <= DateTime.Now.AddDays(-1))


    System.Reflection.FieldInfo fieldInfo = dataRow.GetType().GetField("rowID", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

    int rowID = (int)fieldInfo.GetValue(dataRow);



    Tuesday, December 07, 2010 4:25 AM
  • its  "_rowID" 

    System.Reflection.FieldInfo fieldInfo = row.GetType().GetField("_rowID", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);

    int rowID = (int)fieldInfo.GetValue(row);


    Tuesday, March 01, 2011 6:31 PM