Article View: borland.public.cppbuilder.database.ado
Article #2168Re: TADOTable Out of Order
From: Arnie Mauer
Date: Fri, 31 Oct 2003 16:36
Date: Fri, 31 Oct 2003 16:36
59 lines
3040 bytes
3040 bytes
"Robert Emmons" <remmons@aurigen.com> wrote in message
news:1vv4qvcl4irnt8ln5t1p31ge0cshk96s6s@4ax.com...
> I have a TADOTable (Tbl) in a Jet database with the following fields:
>
> ID1
> Date
> ID2
> Data
>
> The PrimaryKey is ID1, Date, ID2. I display the table in a TDBGrid,
> and set:
>
> DataSource->DataSet->Tbl->Active = true
> DataSource->DataSet->Tbl->IndexName = PrimaryKey
Shouldn't you set the IndexName before you activate the table?
>
> Nevertheless, the table appears in order by ID1, ID2, Date instead of
> by ID1, Date, ID2. If I display the table with Microsoft Access, it
> appears properly in PrimaryKey order.
>
> How can I get the table to appear in proper order in the TDBGrid?
>
An index does not guarantee the order of the returned rows. This is defined
in ANSI SQL. Either use an ORDER BY clause on a query object or the SORT
property of a table object. From BCB Help:
Specifies the sort order of the recordset.
__property WideString Sort = {read=GetSort, write=SetSort};
Description
Set Sort to establish or change the list of fields on which the recordset is
sorted. Set sort to the name of a single field or to a comma-separated list
of fields. Each field may optionally be followed by the keyword ASCENDING or
DESCENDING to specify a sort direction for the field. If one of these
keywords is not used, the default sort direction for the field is ascending.
Set Sort to an empty string to reset the recordset to the sort order
originally used when the recordset's data was first retrieved.
ADOQuery1->Sort = "LastName ASC, DateDue DESC"
Read Sort to determine the field (or fields) on which the recordset is
sorted.
Note: If the cursor is client-side (the dataset component's CursorLocation
property or that of an associated TADOConnection component is clUseClient)
and no index already exists matching the requested field sort order, a
temporary index is created. Resetting the sort order by setting Sort to an
empty string automatically deletes the temporary index.
Hope this helps,
- Arnie
Technical Details
Message-ID:
<3fa28f67@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!in.100proofnews.com!in.100proofnews.com!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<1vv4qvcl4irnt8ln5t1p31ge0cshk96s6s@4ax.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10698b,b4ab9cb102f7ab18 X-Google-Attributes: gid10698b,public X-Google-ArrivalTime: 2003-10-31 08:37:47 PST From: "Arnie Mauer" <xxx@nowhere.net> Newsgroups: borland.public.cppbuilder.database.ado References: <1vv4qvcl4irnt8ln5t1p31ge0cshk96s6s@4ax.com> Subject: Re: TADOTable Out of Order Date: Fri, 31 Oct 2003 11:36:35 -0500 Lines: 61 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 24.151.21.222 Message-ID: <3fa28f67@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1067618151 24.151.21.222 (31 Oct 2003 08:35:51 -0700) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!in.100proofnews.com!in.100proofnews.com!news02.tsnz.net!newsfeed01.tsnz.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail