Solved

Sort content of DBLookUpListBox ?

Posted on 2001-08-04
16
341 Views
Last Modified: 2010-04-06
How to sort content of DBLookUpListBox automatically like what a ListBox Sort property do.
0
Comment
Question by:comicboy
  • 10
  • 5
16 Comments
 
LVL 17

Expert Comment

by:inthe
ID: 6352191
Hi,
using a tquery you can use a "ORDER BY" in the sql statement.
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6352196
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
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6352197
Doggone it inthe you beat me out. hehehe
0
 

Author Comment

by:comicboy
ID: 6352682
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
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6352688
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
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6352691
Here is a link to an online SQL (Structured Query Language) tutorial.

http://w3.one.net/~jhoffman/sqltut.htm
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6352698
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
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6352700
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
Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

 

Author Comment

by:comicboy
ID: 6352711
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
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6353841
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
 

Author Comment

by:comicboy
ID: 6355256
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
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6356130
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
 

Author Comment

by:comicboy
ID: 6356647
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
 
LVL 44

Accepted Solution

by:
CrazyOne earned 50 total points
ID: 6368704
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
 

Author Comment

by:comicboy
ID: 6378987
Great !!! :)) Thanks
It's explain alot...
You're greater expert Crazy One
0
 
LVL 44

Expert Comment

by:CrazyOne
ID: 6379216
You are welcome and thank you. :>)
0

Featured Post

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

747 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now