hog Posted November 6, 2003 Posted November 6, 2003 I'm using a temp machine while mine is in repair and do not have any help installed:( If I have a dataset with say 10 rows is there a way to search the dataset for a row with a given value, something like the old seek method used in VBA? Surely I don't have to code to cycle through each row myself do I?? Quote My website
Administrators PlausiblyDamp Posted November 6, 2003 Administrators Posted November 6, 2003 You could use a DataView and either use it's Rowfilter property or it's Find method. (I think) Quote Posting Guidelines FAQ Post Formatting Intellectuals solve problems; geniuses prevent them. -- Albert Einstein
hog Posted November 6, 2003 Author Posted November 6, 2003 Thanks. Not sure a dataview would be the answer though. I have just found a method in the rows method called Find which may be what I'm after. I shall have a play and see:) Quote My website
*Experts* Nerseus Posted November 6, 2003 *Experts* Posted November 6, 2003 What do you need to do after you find the row? If you need the index, you can use the DataView's Find method. You can do it directly on the datatable by using: ds.Tables[0].DefaultView.Find If you just need a reference to the row that matches, use the Select method: DataRow[] matchingRows = ds.Tables[0].Select("filter goes here"); if(matchingRows.Length > 0) { // Found at least one match: // matchingRows[0] is the first match } Select uses the exact same filtering as a DataView but is much faster if you just need the resulting row. Select doesn't support a Find method though, so if you need the index of the row, it won't work. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
hog Posted November 7, 2003 Author Posted November 7, 2003 Say I have a dataset with 10 rows which has been filled with all the rows pertaining to a particular customer. I then want to search these 10 rows to find the row that has a particular order id, or a particular name etc. I've never used a dataview so am lost on that at the mo? Quote My website
*Experts* Nerseus Posted November 7, 2003 *Experts* Posted November 7, 2003 Again, what's the end result of your finding a row? Do you need the index of the row, a reference to the DataRow, or...? -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
hog Posted November 7, 2003 Author Posted November 7, 2003 Ah....:) gotcha. All I need is to locate and return the datarow Quote My website
*Experts* Nerseus Posted November 7, 2003 *Experts* Posted November 7, 2003 Then I'd use the DataTable's Select method with a filter. -Nerseus Quote "I want to stand as close to the edge as I can without going over. Out on the edge you see all the kinds of things you can't see from the center." - Kurt Vonnegut
hog Posted November 11, 2003 Author Posted November 11, 2003 OK, I'll give this a whirl to see what happens, thnx:) Quote My website
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.