[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 382
  • Last Modified:

Sort content of DBLookUpListBox ?

How to sort content of DBLookUpListBox automatically like what a ListBox Sort property do.
0
comicboy
Asked:
comicboy
  • 10
  • 5
1 Solution
 
intheCommented:
Hi,
using a tquery you can use a "ORDER BY" in the sql statement.
0
 
CrazyOneCommented:
Well you could use a Query and then do an "ORDER BY TheField" so the return set is sorted by that field.


The Crazy One
0
 
CrazyOneCommented:
Doggone it inthe you beat me out. hehehe
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
comicboyAuthor Commented:
Thanks experts,

Anyway I'm new to database and never use TQuery before, please explain step by step, after I place the TQuesry Component ? or what ?
0
 
CrazyOneCommented:
A simple Query would be like this. Click on the TQuery component that you placed on the form and hit the F11 key to bring up the property page. Now scroll down the where you see the SQL property. Double click in the box that is to the right of this property and do this.

SELECT * FROM TheTable
ORDER BY TheField

The asterik is a symbol that indicates to the database that to load all the fields in the table. Where I put the word "TheTable" you need to substitute the name of the table in you are wanting to retrieve from and where I put the word "TheField" is the name of the field in the table you want to have the return result set sorted on.
0
 
CrazyOneCommented:
Here is a link to an online SQL (Structured Query Language) tutorial.

http://w3.one.net/~jhoffman/sqltut.htm
0
 
CrazyOneCommented:
There are a lot of things you can do with a Query and I would suggest spending a lot of time learning how to use them because they are very useful in retrieving data from a database especially when the data you are looking for is very specific in nature. :>)
0
 
CrazyOneCommented:
Also if the table in question has an Index for the field you want sorted you can use the TTable component and tell it to use the Index in question which should return a result set that is sorted on that field.
0
 
comicboyAuthor Commented:
Hi CarzyOne,

Thanks for your advice, I follow, I put TQuerry component (A box with SQL mark on it right ? ) then in property I fill :

DatabaseName to my DatabaseName (I use BDE)
Datasource to my Table name which is T_StockDetail
Then I place in SQL property this :

SELECT * FROM T_StockDetail
ORDER BY Nama

My program OnCreate already do T_StockDetail.Active := true;

and my Close doing the Active := False;

The I put T_StockDetail display on a DBStringGrid and nothing happen ??
0
 
CrazyOneCommented:
Ok what is the name of the TQuery component? The TQuery component is what needs to be set in the DataSource component. When comes to the TQuery and hooking it into the other components just treat it the same way you would the TTable component. Also if you want the data being displayed to be editable make sure to set the TQuery RequestLive property to True. Also make sure you set the Query Active to true so it is opened.

Here is another trick: Instead of setting Active to true in your code you can use the method "Open" and to close it you can use the method "Close". :>)
0
 
comicboyAuthor Commented:
CrazyOne,

I've tried what you've suggest by applying the Query component to DataSource component (treat as Table) and do Query.Active := true;

The what I've got it show a dialog says :
"T_StockDetail.DBF" not found
"T_StockDetail.IDX" not found
"T_StockDetail.TXT" not found
"T_StockDetail." not found

or somekind like that.

Anyway what is the advantage of using Open instead of Active := true ?
0
 
CrazyOneCommented:
Ok have you assigned a database name to the Query. Do it the same way you do it for a TTable.

>>>Anyway what is the advantage of using Open instead of Active := true ?

Not much other then you don't have to assign a Boolean expression to it. In other words when one reads the code and sees Open they know that that is where the dataset gets opened. However when one reads the code and sees Active they have to look to see if it is set to true or false to deterimine whether it is open or not.
0
 
comicboyAuthor Commented:
Hi CrazyOne,
To make sure I've done nothing wrong, I delete and replace the TQuery and TDataSource Component, I Call Q_StockDetail for the TQuery and DS_StockDetailQuery for the TDataSource.

I already has another TTable called T_StockDetail and TDataSource called DS_StockDetail which binding T_StockDetail for doing something else like edit the current stock detail.

I bind DS_StockDetail to Q_StockDetail.DataSource then I'm already put my database name to Q_StockDetail.DatabaseName also not forget to fill the SQL statement.

After that I bind Q_StockDetail to DS_StockDetailQuery.DataSource this TDataSource is used for the DBListBox and DBStringGrid to display StockDetail sorted by "Name" field.

But still the same error occur :( ...

Thanks :) actually for this school assignment I'm creating a simple inventory system for my school.

This is the field of T_StockDetail :

Code (Alpha 4 => Key Index)
Name (Alpha 8)
Amount (Integer)
Explaination (Alpha 16)

in Paradox and BDE

Thanks
0
 
CrazyOneCommented:
Hi comicboy sorry for the Delay. Ok for testing purpose try this.

With the Q_StockDetail make sure that the DatabaseName property is pointing to the correct Database and make sure the DataSource property is empty. Now make sure you have the correct statement in the SQL property.

Now set the DataSet property of the DS_StockDetailQuery to Q_StockDetail. Now drop a DBGrid onto your form and set the DataSource property to DS_StockDetailQuery. Now go back to the Q_StockDetail and set the Active property to True. If everything is setup correctly and there is data in the table you are querying then you should see that data in the grid. You don't have to compile your project for this test. Just do it all in the design mode. If this does not work please post the following

Q_StockDetail.SQL Statement
Q_StockDetail.DatabaseName
Q_StockDetail.DataSource
DS_StockDetailQuery.DataSet
DBGrid.DataSource
0
 
comicboyAuthor Commented:
Great !!! :)) Thanks
It's explain alot...
You're greater expert Crazy One
0
 
CrazyOneCommented:
You are welcome and thank you. :>)
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now