Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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??

My website
Posted

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:)

My website
  • *Experts*
Posted

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

"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
Posted

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?

My website
  • *Experts*
Posted

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

"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
  • *Experts*
Posted

Then I'd use the DataTable's Select method with a filter.

 

-Nerseus

"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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...