Skip to Content
author's profile photo Former Member
Former Member

The order of a DBDataSource - A unique key (index) can help (but...)

Hi @all!

There was often the question, if a DBDataSource could be ORDERed BY sth. Although it would be nice if somebody could disprove that: It's not possible.

Up to this my experience was that the "items" in a DBDataSource always ordered by the Code-Column. That's what my code in some situations relys on. For example if a B1-form browses by a DBDataSource then the order is not always user friendly based on a column with data the user knows.

But today I was surprised: "Suddenly" a DBDataSource-browsing form is browsing correctly by a DB-Column which the user is interested in (instead of the code-column) !

The reason for this is a unique UserKey, which I've created by SDK (UserKeysMD). The form seems to browse by the columns of the key.

But the common reason seems to be that it's standard SQL-behaviour because doing a simple query (without ORDER BY) in SQL-Management Studio also sorts the results by the unique key.

But there's one important question left:

Which key wins and why? There's also the unique index for Code on that table....



Add a comment
10|10000 characters needed characters exceeded

Related questions

1 Answer

  • Best Answer
    author's profile photo Former Member
    Former Member
    Posted on Apr 08, 2008 at 02:11 PM


    it flustrating, but it seems that datasource is sorting it randomly (depends on indexes in table). That was the reason why Im using datatables with order by statement instead of datasources...


    Add a comment
    10|10000 characters needed characters exceeded

    • Former Member David Nussböck

      Thanks David & Petr,

      your statements and wishes have brought me forward in my decision to do it another way.

      What I'm doing now (and it already seem to work 😊) ...:

      - Loading a DataTable (not bounded) only with the Code-Cols ORDERed by the things THAT I WANT. Since a DataTable also provides an Offset-property (like DBDataSource) it was easier to re-implement than a RecSet.

      - On every yellow-arrow step the offset is switched for-/backward regarding the beginnng and ending (stepping is cycling)

      - On every yellow-arrow step the already existing DBDataSource is loaded with the condition of "Code equals the code of the actual step"

      Performance is ok (and mostly influenced by another SELECT...which has leaded to the indexes....which leads back to the start of this thread).

      (happy end - tachacka 😉)



Before answering

You should only submit an answer when you are proposing a solution to the poster's problem. If you want the poster to clarify the question or provide more information, please leave a comment instead, requesting additional details. When answering, please include specifics, such as step-by-step instructions, context for the solution, and links to useful resources. Also, please make sure that you answer complies with our Rules of Engagement.
You must be Logged in to submit an answer.

Up to 10 attachments (including images) can be used with a maximum of 1.0 MB each and 10.5 MB total.