Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
How to find a row on text in a column?
Message
De
20/03/2010 13:07:44
 
 
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
C# 2.0
Divers
Thread ID:
01455096
Message ID:
01455848
Vues:
62
>My purpose is not to prove who is right or who is wrong. I was just trying find a way to quickly search through a dataset/datatable for a row in the datatable by a value in a column. And it looks like setting the field name to Sort property of DataView (which I didn't create so I guess it is there - in dataset - automatically) allow the searching. And my dataset didn't have to have a primary key. Unless I am missing something.

I wasn't saying you were wrong. I was pointing out that DataTable and DataView are different. No, you didn't create a DataView, but every DataTable has a DefaultView, which is the one you used I assume, since that is the only way to set the .Sort property.

You also need to be careful because using the .Find() method of a DataTable is different than using the .Find() method of the table's DefaultView. If you set the .Sort property of the DefaultView, then use the .Find() method of the DefaultView (which you would have had to use if you had no PK defined on the DataTable), then that .Find() method returns an integer which is an index of the found row. HOWEVER, it is an index to the row in the DefaultView, NOT the DataTable!! Important thing to remember!

IOW, MyDataTable.Rows[x] may not point to the same row as MyDataTable.DefaultView[x].

~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform