Re: Problem with Recordset Find method
From: David Schlecht (dschl_at_earthlink.net)
Date: 11/11/04
- Next message: Paul Clement: "Re: ADO.NET"
- Previous message: blueman: "ADO.NET"
- In reply to: Mona \(Grapecity\): "Re: Problem with Recordset Find method"
- Messages sorted by: [ date ] [ thread ]
Date: 11 Nov 2004 10:24:13 -0800
Reading the posts on this and related newsgroups, it becomes apparent
that
the MS implementation of the ADO .Find method is so broken that almost
every
developer has given it up for worthless and recommends using a new
recordset to find the the one or few records you need.
Here's what I have found. Hopefully it will help:
In ADO 2.5
.Find doesn't check the current record, so if your target is in the
current record, MS blindly throws an EOF.
In order to work around this, try checking the current record before
using
.Find.
If rs!field <> target then
rs.Find "field = " & target
end if
Of course, you could use the "SkipRecords" optional argument to .Find
and
tell it to adBookmarkFirst, but you'd be crazy to expect something
different
(working, usable software) by using the same old thing. It doesn't
work, either.
Also, adBookmarkFirst doesn't actually start searching at the first
record (did you really expect it to work?) so you must do a .MoveFirst
before the .Find
If there are better alternatives, I'd love to hear them.
-Dave
"Mona \(Grapecity\)" <mona@discussions.microsoft.com> wrote in message news:<OtVxMIVxEHA.3844@TK2MSFTNGP09.phx.gbl>...
> Hi Paul,
>
> Well,for the starters I would suggest you to make your RowId as a primary
> key in your database because in that case the field will be automatically
> indexed and sorted and you wouldn't have to do it explicitly.
>
> But also, I tried the same code for a field which is not a primary key in my
> database and can be duplicated (Names) and it works absolutely fine for
> me!!!
>
> So, you can make the required changes in the database and see whether it
> works for you or not.If the problem persists then probably there's something
> else in your code that could be creating a problem so you can send in more
> information to enable me to help you better.
>
> HTH
> Mona
>
>
>
> "PaulW" <MSNewsGroup@Digi-Sol.com> wrote in message
> news:O5$b6wdtEHA.3152@TK2MSFTNGP14.phx.gbl...
> > Hi,
> >
> >
> >
> > I tried to create an index on the field in the record set.
> >
> >
> >
> > DCtblData.Recordset.moveFirst
> >
> > DCtblData.Recordset.Fields("RowID").Properties("Optimize") = True
> >
> > DCtblData.Recordset.moveFirst
> >
> > DCtblData.Recordset.Find "RowID = '" & rowID & "'", 0, adSearchForward
> >
> >
> >
> > This didn't help. If I sorted the record set by the RowID column, then the
> > Find worked.
> >
> >
> >
> > DCtblData.Recordset.Sort = "RowID"
> >
> >
> >
> > I cannot keep sorting the record set. The displayed data order will be
> > changing on the user for no apparent reason (to him), not to mention the
> > time required to perform the sort.
> >
> >
> >
> > Paul
> >
> >
> >
> > "PaulW" <MSNewsGroup@Digi-Sol.com> wrote in message
> > news:u2FFSKWtEHA.412@TK2MSFTNGP14.phx.gbl...
> > > Hi,
> > >
> > >
> > >
> > > I am using an ADO record set object in an ASP page.
> > >
> > >
> > >
> > > <object CLASSID="clsid:BD96C556-65A3-11D0-983A-00C04FC29E33"
> ID="DCTblData">
> > >
> > > <param NAME="SERVER" VALUE="<%=Application("RDSConnStr")%>">
> > >
> > > </object>
> > >
> > >
> > >
> > > The following code correctly always finds the record in question:
> > >
> > >
> > >
> > > DCtblData.Recordset.moveFirst
> > >
> > > Do While Not DCtblData.Recordset.EOF
> > >
> > > If( DCtblData.Recordset.fields.item("RowID") = rowID ) Then
> > >
> > > MsgBox "Got It"
> > >
> > > Exit Do
> > >
> > > End If
> > >
> > > DCtblData.Recordset.moveNext
> > >
> > > Loop
> > >
> > >
> > >
> > > The following code does NOT find the matching rowID and returns the EOF.
> > > There are times when it does find a match, confusing:
> > >
> > >
> > >
> > > DCtblData.Recordset.moveFirst
> > >
> > > DCtblData.Recordset.Find "RowID = '" & rowID & "'", 0, adSearchForward
> > >
> > > MsgBox " EOF: " & DCtblData.Recordset.EOF
> > >
> > >
> > >
> > >
> > >
> > > Any ideas? Can it some how be data dependent?
> > >
> > >
> > >
> > > Tia
> > >
> > > Paul
> > >
> > >
> >
> >
- Next message: Paul Clement: "Re: ADO.NET"
- Previous message: blueman: "ADO.NET"
- In reply to: Mona \(Grapecity\): "Re: Problem with Recordset Find method"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|