How to find index\position of record in VB.Net Dataset

leeland

Diamond Member
Dec 12, 2000
3,659
0
76
OK...here is what I have so far.

1. Query the DB to pull in the inital view of information and dump that into a dataset.

2. copy that information to a dataview for the purpose of using another winform for a seach page.

I attach the dataview to a list box. When the user types in the text box I use a rowfilter routine to filter the listbox so as they type in a name the list shortens until only the name you want displays in the listbox

I want to use that name to search on the first form to populate a bunch of other text boxes.

3. Pass the name back to the first form and populate a text box with the name.


THIS IS WHAT I CAN"T FIGURE OUT.

I want to use that name that I have from my search to then find the correct position in the original dataset...so I can find the position in the dataset and then set that row as the current row and use the fields from that record to populate a bunch of other text boxes...

Problem I have is I don't know how to construct the code to search\query a dataset...what ever I have come up with doesn't give me squat...

So if anyone has some hints I would greatly appreciate it.
 

TheUnk

Golden Member
Jun 24, 2005
1,810
0
71
You could just loop through it, since a dataset is basically just an array.


For i = 0 To ds.Tables("myTable").Rows.Count - 1
If ds.Tables("myTable").Rows(i).Item("myColumn") = strName Then
'row position = i
End If
Next
 

leeland

Diamond Member
Dec 12, 2000
3,659
0
76
Originally posted by: TheUnk
You could just loop through it, since a dataset is basically just an array.


For i = 0 To ds.Tables("myTable").Rows.Count - 1
If ds.Tables("myTable").Rows(i).Item("myColumn") = strName Then
'row position = i
End If
Next

Thanks for the reply first of all and thanks for the code.


Do you know of any other way that it can be done where you don't have to loop through ? Not that it wouldn't work and if I can't find a different way I will probably ahve to do it that way.

Just curious.

Thanks again TheUnk

Lee
 

TheUnk

Golden Member
Jun 24, 2005
1,810
0
71
Sorry, I don't know of another way.. Unless you have millions of rows the code should be very fast, just put an Exit For in there when you find the row you want.
 

phantom404

Golden Member
Nov 2, 2004
1,460
2
81
What about an sql statement. Something saying Select * from dataset where name=listbox.text

Listbox.text is where the user types in what to search for
name is what ever you want to match listbox.text with in the database.

You can also create another form called 'formglobal' and use that to pass variables back and forth from forms. You could use it to do the same thing to datasets im sure.
 

leeland

Diamond Member
Dec 12, 2000
3,659
0
76
Originally posted by: phantom404
What about an sql statement. Something saying Select * from dataset where name=listbox.text

Listbox.text is where the user types in what to search for
name is what ever you want to match listbox.text with in the database.

You can also create another form called 'formglobal' and use that to pass variables back and forth from forms. You could use it to do the same thing to datasets im sure.


That is what I was hoping to do...however I have a global variable that holds the name value.

so I am basically looking for an example or the syntax of how you would query a dataset when you have criteria to search for.