where clause or something similar for dataview.find?

G

Guest

Greetings,

I need to locate a row (or see if it exists) in a table contained in a
dataset. The DataView.Find method seems to work OK for one criteria but I
need to use 2 criterias. Is there anything in VB2005 that does was DLookUpd
does in Access - but for a table contained in a Dataset? I realize that
DLookUp works on Physical tables (not in-memory dataset tables), and I could
use a sqlDataReader to find my row from the physical table. But I am hoping
there is a way to find this row in the dataTable of the data that I have
already pulled (Ideally without having to loop through each row - althought,
that is my alternative).

Thanks,
Rich
 
R

RobinS

From Dave Sceppa's ADO.Net Core Reference. I kind of merged info from a
couple of different places together. Hope it leads you in the right
direction.

The Find method is overloaded in case you have multiple columns in your
primary key.You can specify a single value or an array of values. It
returns an integer value that corresponds to the index of the desired row
in the DataView. If can't find it, it returns -1.

Dim dv as New DataView(dt) 'dt is Customers table
Dim Index As Integer = dv.Find("Fran Wilson")
If Index = -1 Then
'not found
Else
Console.WriteLine(dv(Index)("CompanyName"))
End If

This is how he shows doing it with multiple columns against a datatable, to
get a set of rows. I think the methodology for using the array would be the
same for a dataview.

dt.PrimaryKey = New DataColumn() {dt.Columns("OrderID"),
dt.Columns("ProductID")}
Dim objCriteria As New Object() {10643, 28}
Dim row As DataRow = dt.Rows.Find(objCriteria)

He ties sorting and Find together in his book.

Robin S.
Ts'i mahnu uterna ot twan ot geifur hingts uto.
 
G

Guest

Thanks for your reply. It looks like good information. Close of business
day now, so I will try it out in the morning.

Thanks,
Rich
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top