Search code examples
c#dataview

Retrieving rows in DataView by its index


I have a DataView, which has been sorted in some order. How can I retrieve the values using an index.

Something like this:

if(dv.rows[0]["name"]=="xxx")  
{  
  --- do something ---  
}  
else  
  --- something else ---  

Solution

  • Try the following code

    Move the sorted DataView to DataTable like

    DataTable dt = dv.ToTable(); 
    

    Then use

    if (dt.Rows[0]["name"] == "xxx")
    {
      [...]
    }
    

    It will work.