DataView’s Find and FindRows

Several days ago, I tried using Find/FindRows to find a row in a DataView.
Checking MSDN, I found that these methods requested an object that is the key to use.
I used the DataTable’s key, but the row was not found even though it was in the DataView.

After some investigation using Reflector, I found that the key requested was actually the column used for sorting the DataView. Once there is no custom sort order, the key used is the DataTable’s key.
Anyone got any idea why the heck this is?


4 thoughts on “DataView’s Find and FindRows

  1. DataRow[] rows = dataTable.Select("name = ‘uuu’", "name, id DESC")

    – or –

    dataView.Sort = "name";
    DataRowView[] rows = dataView.FindRows("uuu");

    – or –

    some kind of [] for multiple colums for dataView.FindRows

    I really hate data views

  2. I’ve been using the code that name provided, have tryed each of the formats, but i keep on getting the following error:
    “Input string was not in a correct format”
    I’m working from an excel spreadsheet, which I’ve converted into a dataset with datatbles.
    DataRowView[] rvFound = Dataset1.Tables[0].DefaultView.FindRows(“Mineral = ‘Alumina'”);

  3. mj, please read it again…
    You are using the wrong method for your approach, should be:
    DataRowView[] rvFound = Dataset1.Tables[0].DefaultView.Select(“Mineral = ‘Alumina'”);

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s