Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Sort content of DBLookUpListBox ?

Posted on 2001-08-04
16
Medium Priority
?
373 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 

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
 

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 200 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

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!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
This course is ideal for IT System Administrators working with VMware vSphere and its associated products in their company infrastructure. This course teaches you how to install and maintain this virtualization technology to store data, prevent vuln…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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