Delphi Pages Forums  

Go Back   Delphi Pages Forums > Delphi Forum > General

Lost Password?

Closed Thread
 
Thread Tools Display Modes
  #1  
Old 10-04-2016, 03:35 PM
golden_eyes golden_eyes is offline
Senior Member
 
Join Date: Dec 2005
Posts: 382
Default Dinamically search using Tquery

Hello,

I have a form contain dbgrid, which show 10 columns, I have also another form contain all TEdit objects. My Question is what is the best way to search when press on the Button using the TQuery? rather than the old fashion

Code:
  if (Length(Edit1.Text) > 0) then
    sFilter:= 'file_no like ' + QuotedStr(Edit1.Text);

  if ((Length(sFilter) > 0) and (Length(Edit2.Text) > 0)) then
    sFilter:= sFilter + ' and ';

  if Length(Edit2.Text) > 0 then
    sFilter:= sFilter + 'parent_no like' + QuotedStr(Edit2.Text);

  if ((Length(sFilter) > 0) and (Length(Edit3.Text) > 0)) then
    sFilter:= sFilter + ' and ';
Be aware that I could search in more than field at the same time

select * from table where abc = 1 and efg = 2 etc....

Regards
  #2  
Old 10-05-2016, 12:21 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

By building an SQL statement based on the values entered in the TEdit's. Similar to the code that you use in the filter.
__________________
Regards,
Abdulaziz Jasser
  #3  
Old 10-05-2016, 02:27 PM
golden_eyes golden_eyes is offline
Senior Member
 
Join Date: Dec 2005
Posts: 382
Default

Is this this the best way? or there is another way more professional to build the query under runtime?

As you the select * from table where 1=1 and a=3 and b not like 4 etc... is too complicated qry

Anyway thank you for your reply and really I love Delphi.

Regards
  #4  
Old 10-05-2016, 04:51 PM
Jasser Jasser is offline
Moderator
 
Join Date: Jan 2005
Location: Saudi Arabia
Posts: 5,059
Default

I think this is the best way.


Just make sure you have the right indexes to support your query.

You may need to involve the DB administrator to help you on best way to run an SQL query.

Good luck to you...
__________________
Regards,
Abdulaziz Jasser
Closed Thread

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On

Forum Jump


All times are GMT. The time now is 12:09 AM.


Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2019, vBulletin Solutions, Inc.