Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with the TSQLQuery component

Status
Not open for further replies.

CarrahaG

Programmer
Mar 25, 2007
98
AW
Hello

I am programming in Delphi 2006 using the TSQLQuery for the first time and have not been successful.

I have a MSSQL database called FDD and it has a table called USERS. I am trying to list only the USERS in a DBGrid that start with "G".

I have done the following:

1. Added a TSQLConnection component called SQL SQLConnectionFDD.
2. Added a TSQLDataSet component called SQLDataSetUSERS which has the SQL Connection value set to SQLConnectionFDD.
3. Added a TDataSetProvider component called DataSetProviderUSERS which has the DataSet value set to SQLDataSetUSERS.
4. Added the TClientDataSet component called ClientDataSetUSERS which has the ProviderName set to DataSetProviderUSERS
5. Added the TDataSource component called DataSourceUSERS which has the DataSet set to ClientDataSetUSERS.
6. Added the TDBGrid component called DBGridUSERS which has the DataSource set to DataSourceUSERS.


At this point I have no problem to see all the records in the USERS table in the DBGrid.

I now want to reduce what is being shown in the DBGrid.

I then add the TSQLQuery component called SQLQueryUSERS which has the DataSource set to DataSourceUSERS and the SQL Connection value set to SQLConnectionFDD. I also set the SQL value to "SELECT * FROM USERS WHERE USER_ID WHERE LIKE 'G%'". I also set the component to Active.

It still lists all the records.

What am I doing wrong?

Regards,
Georges
 
I don't work with the clientdatasets much so I'll ask some basic questions:

Are you meaning to use the TSQLQuery in a master-detail way? It appears you are by setting the source of the TSQLQuery to be a TDatasource.

Can you connect your TSQLQuery directly to your TSQLConnection and execute the query like that?
 
Hello DjanMan

I am setting the SQLConnection property of the SQLQueryUSERS component to be SQLConnectionFDD which is the TSQLConnection component;

Regards,

 
You need to get your DataSetProvider's Dataset property to point to your SQLQueryUsers component.

The reason that you are still getting ALL your records is because the DataSetProvider is getting its records from the SQLDataSetUsers component instead of SQLQueryUsers.

You may have to close your ClientDataSet before changing the DSP and then reopen it. I can't remember offhand.



Andrew
Hampshire, UK
 
Hello Towerbase

Your advice worked. Thank you very much.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top