FIND like old ADO method

T

Tom

Is there any kind of FIND in ADO.NET that works the same way as the old ADO
Recordset FIND? The old ADO Find would accept a criteria string, and then
find the first record that matches the criteria. For instance,

rs.Find("text_value like '* | *')

would position me on the first record that contained a bar (' | '). It
didn't filter anything, but just positioned the database at that record (or,
in ADO.NET, would give me the row index of the first record matching this
criteria).

I see SELECT on a datatable and ROWFILTER on a dataview, but these all
filter... I simply want to find the first record matching this criteria.

I can probably get around it by simply reading all the records and
programatically searching for the first one that matchs, but was hoping for
a built-in solution.

Thanks in advance.

Tom
 
M

Miha Markic

Hi Tom,

There is no built in solution - you have either do it in database (WHERE
clause) or load all suitable data and search through records (perhaps using
DataTable.Select method).
 
B

Bernie Yaeger

Hi Tom,

You can set up a dataview of a datatable in a dataset and use the .find
method it provides.

Here's a skeleton of the structure:
Dim arrayseekp(1) As Object

Dim ifindp As Integer

Dim vuep As New DataView(dsprod.Tables(0))

vuep.Sort = "bipad, issuecode"

arrayseekp(0) = "12345"

arrayseekp(1) = 022001

ifindp = vuep.Find(arrayseekp)

dim xvar as string

If ifindp <> -1 Then ' ie, found it

xvar = vuep(ifindp)("title")

end if

There is a similar method you can use in the datatable's defaultview, but I
find this easier. Note: this does not require a seek on the PK - any
column(s) will do.

HTH,

Bernie Yaeger
 

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