Article View: borland.public.cppbuilder.database.ado
Article #1412Re: BETWEEN use in TADODataSet
From: Viatcheslav V. Vassiliev
Date: Wed, 14 Jul 2004 12:15
Date: Wed, 14 Jul 2004 12:15
137 lines
7697 bytes
7697 bytes
BETWEEN is not supported in Filter. User (Column >= X AND Column <= Y). It
is description of Filter from MSDN:
Use the Filter property to selectively screen out records in a Recordset
object. The filtered Recordset becomes the current cursor. Other properties
that return values based on the current cursor are affected, such as
AbsolutePosition, AbsolutePage, RecordCount, and PageCount. This is because
setting the Filter property to a specific value will move the current record
to the first record that satisfies the new value.
The criteria string is made up of clauses in the form
FieldName-Operator-Value (for example, "LastName = 'Smith'"). You can create
compound clauses by concatenating individual clauses with AND (for example,
"LastName = 'Smith' AND FirstName = 'John'") or OR (for example, "LastName =
'Smith' OR LastName = 'Jones'"). Use the following guidelines for criteria
strings:
FieldName must be a valid field name from the Recordset. If the field name
contains spaces, you must enclose the name in square brackets.
Operator must be one of the following: <, >, <=, >=, <>, =, or LIKE.
Value is the value with which you will compare the field values (for
example, 'Smith', #8/24/95#, 12.345, or $50.00). Use single quotes with
strings and pound signs (#) with dates. For numbers, you can use decimal
points, dollar signs, and scientific notation. If Operator is LIKE, Value
can use wildcards. Only the asterisk (*) and percent sign (%) wild cards are
allowed, and they must be the last character in the string. Value cannot be
null.
Note To include single quotation marks (') in the filter Value, use two
single quotation marks to represent one. For example, to filter on O'Malley,
the criteria string should be "col1 = 'O''Malley'". To include single
quotation marks at both the beginning and the end of the filter value,
enclose the string with pound signs (#). For example, to filter on '1', the
criteria string should be "col1 = #'1'#".
There is no precedence between AND and OR. Clauses can be grouped within
parentheses. However, you cannot group clauses joined by an OR and then join
the group to another clause with an AND, like this:
(LastName = 'Smith' OR LastName = 'Jones') AND FirstName = 'John'
Instead, you would construct this filter as
(LastName = 'Smith' AND FirstName = 'John') OR (LastName = 'Jones' AND
FirstName = 'John')
In a LIKE clause, you can use a wildcard at the beginning and end of the
pattern (for example, LastName Like '*mit*'), or only at the end of the
pattern (for example, LastName Like 'Smit*').
The filter constants make it easier to resolve individual record conflicts
during batch update mode by allowing you to view, for example, only those
records that were affected during the last UpdateBatch method call.
Setting the Filter property itself may fail because of a conflict with the
underlying data (for example, a record has already been deleted by another
user). In such a case, the provider returns warnings to the Errors
collection but does not halt program execution. A run-time error occurs only
if there are conflicts on all the requested records. Use the Status property
to locate records with conflicts.
Setting the Filter property to a zero-length string ("") has the same effect
as using the adFilterNone constant.
Whenever the Filter property is set, the current record position moves to
the first record in the filtered subset of records in the Recordset.
Similarly, when the Filter property is cleared, the current record position
moves to the first record in the Recordset.
When a Recordset is filtered based on a field of some variant type (e.g.,
sql_variant), an error (DISP_E_TYPEMISMATCH or 80020005) will result if the
subtypes of the field and filter values used in the criteria string do not
match. For example, if a Recordset object (rs) contains a column (C) of the
sql_variant type and a field of this column has been assigned a value of 1
of the I4 type, setting the criteria string of rs.Filter = "C='A'" on the
field will produce the error at run time. However, rs.Filter = "C=2" applied
on the same field will not produce any error although the field will be
filtered out of the current record set.
See the Bookmark property for an explanation of bookmark values from which
you can build an array to use with the Filter property.
Only Filters in the form of Criteria Strings (e.g. OrderDate > '12/31/1999')
affect the contents of a persisted Recordset. Filters created with an Array
of Bookmarks or using a value from the FilterGroupEnum will not affect the
contents of the persisted Recordset. These rules apply to Recordsets created
with either client-side or server-side cursors.
Note When you apply the adFilterPendingRecords flag to a filtered and
modified Recordset in the batch update mode, the resultant Recordset is
empty if the filtering was based on the key field of a single-keyed table
and the modification was made on the key field values. The resultant
Recordset will be non-empty if one of the following is true:
The filtering was based on non-key fields in a single-keyed table.
The filtering was based on any fields in a multiple-keyed table.
Modifications were made on non-key fields in a single-keyed table.
Modifications were made on any fields in a multiple-keyed table.
//------------------------------------------
Regards,
Vassiliev V. V.
http://www.managed-vcl.com - using .Net objects in Delphi for Win32 +
ADO.Net
http://www.oledbdirect.com - The fastest way to access MS SQL Server,
MS Jet (Access) and Interbase (through OLEDB)
"Michele Santucci" <michele.santucci.nospam@nospam.celinavio.it>
�������/�������� � �������� ���������:
news:40f51e09@newsgroups.borland.com...
> I'm trying to use a BETWEEN statement in a .Filter property of a
TADODataSet
> component.... but each time I try I got an EOleException and an error
about
> parameters of wrong type, out of bounds or conflicting.
> This's a portion of the "non working" code :
>
> AnsiString Filter = "";
>
>
> dmTargetDB->adodsPlatform->Filtered = false;
>
> for(int i=0; i<QueryItems->Count; i++)
> Filter += (*(AnsiString*)QueryItems->Items->Objects[i]);
>
>
> dmTargetDB->adodsPlatform->Filter = Filter;
>
> dmTargetDB->adodsPlatform->Filtered = true;
>
> dbgActors->Refresh();
>
> P.S. I have problems only with BETWEEN statement other one such as >, =, <
> are working fine.
>
> --
> ================================
> Michele Santucci
> Software Development Manager
> Celin Avio S.r.l.
> Via Fontevivo, 21/M 19100 La Spezia
> tel. +39-0187564080
> ================================
>
>
Technical Details
Message-ID:
<40f523f9@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<40f51e09@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 10698b,c62bd2de5c3295a9 X-Google-Attributes: gid10698b,public X-Google-Language: ENGLISH,ASCII From: "Viatcheslav V. Vassiliev" <support@oledbdirect.com> Newsgroups: borland.public.cppbuilder.database.ado References: <40f51e09@newsgroups.borland.com> Subject: Re: BETWEEN use in TADODataSet Date: Wed, 14 Jul 2004 16:15:54 +0400 Lines: 139 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 213.234.218.42 Message-ID: <40f523f9@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1089807353 213.234.218.42 (14 Jul 2004 05:15:53 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!logbridge.uoregon.edu!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail