If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > Delphi, C etc > A search for a few options in the Database

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 05-31-09, 03:13
mina.azarm mina.azarm is offline
Registered User
 
Join Date: May 2009
Posts: 1
A search for a few options in the Database

hello

i use this code can easily exactly filter their bank to get information.


var
sFilter : String;
begin
DBGrid3.DataSource.DataSet.Filtered := False;

sFilter := '';

if ch1.Checked then begin
if sFilter <> '' then
sFilter := sFilter + ' OR ';

sFilter := sFilter + ' (position = '+ QuotedStr(ech1.Text) + ')';
end;

if ch2.Checked then begin
if sFilter <> '' then
sFilter := sFilter + ' AND ';

sFilter := sFilter + ' (testimony = '+ QuotedStr(ech2.Text) + ')';
end;

if ch3.Checked then begin
if sFilter <> '' then
sFilter := sFilter + ' AND ';

sFilter := sFilter + ' (sex = '+ QuotedStr(ech3.Text) + ')';
end;

if ch4.Checked then begin
if sFilter <> '' then
sFilter := sFilter + ' AND ';

sFilter := sFilter + ' (organization = '+ QuotedStr(ech4.Text) + ')';
end;

if ch5.Checked then begin
if sFilter <> '' then
sFilter := sFilter + ' AND ';

sFilter := sFilter + ' (age = '+ QuotedStr(ech5.Text) + ')';
end;


DBGrid3.DataSource.DataSet.Filter := sFilter;
DBGrid3.DataSource.DataSet.Filtered := True;
DBGrid3.DataSource.DataSet.First;
label49.caption:=Inttostr(adotable3.recordcount);


Now I want the same code filter for some option i use. But it does not work.
Of course I number of fileds and maintaining more than that for example, just as much as I have written.

I asked if I checked time: 4 and checked "saturday" and "sanday" day field.
The only people who list of their time in 4 hours and days are saturday and Sunday to show or for example, if I checked 4 and 8 time and checked saturday and sunday, I chose program only to those who list in 4 and 8 and in the days are saturday and Sunday to show me.

my CheckedComboBox is enhanced CheckedComboBox 1.4 freeware.

var
gfilter1 : string;

begin
DBGrid4.DataSource.DataSet.Filtered := False;
gfilter1 := '';

if CheckedComboBox1.Checked[0] then begin
if gFilter1 <> '' then
gFilter1 := gFilter1 + ' OR ';

gFilter1 := gFilter1 + Format(' (time = %s)',[QuotedStr('0')]);
end;
if CheckedComboBox1.Checked[1] then begin
if gFilter1 <> '' then
gFilter1 := gFilter1 + ' OR ';

gFilter1 := gFilter1 + Format(' (time = %s)',[QuotedStr('4')]);
end;
if CheckedComboBox1.Checked[2] then begin
if gFilter1 <> '' then
gFilter1 := gFilter1 + ' OR ';

gFilter1 := gFilter1 + Format(' (time = %s)',[QuotedStr('8')]);
end;


if CheckedComboBox2.Checked[0] then begin
if gFilter1 <> '' then
gFilter1 := gFilter1 + ' OR ';

gFilter1 := gFilter1 + Format(' (daycount = %s)',[QuotedStr('all day')]);

end;
if CheckedComboBox2.Checked[1] then begin
if gFilter1 <> '' then
gFilter1 := gFilter1 + ' OR ';

gFilter1 := gFilter1 + Format(' (daycount = %s)',[QuotedStr('saturday')]);
end;

if CheckedComboBox2.Checked[2] then begin
if gFilter1 <> '' then
gFilter1 := gFilter1 + ' OR ';

gFilter1 := gFilter1 + Format(' (daycount = %s)',[QuotedStr('sunday')]);
end;

if CheckedComboBox2.Checked[2] then begin
if gFilter1 <> '' then
gFilter1 := gFilter1 + ' OR ';

gFilter1 := gFilter1 + Format(' (daycount = %s)',[QuotedStr('mondy')]);
end;

DBGrid4.DataSource.DataSet.Filter := gFilter1;
DBGrid4.DataSource.DataSet.Filtered := True;
DBGrid4.DataSource.DataSet.First;
label52.caption:=Inttostr(adotable4.recordcount);
Reply With Quote
  #2 (permalink)  
Old 06-05-09, 18:03
Tyveleyn Tyveleyn is offline
Registered User
 
Join Date: Aug 2006
Location: The Netherlands
Posts: 248
Hi,

put a
Code:
ShowMessage(gFilter1);
right before
Code:
DBGrid4.DataSource.DataSet.Filter := gFilter1;
and check the syntax of the filter and it's operands.
Especially date and time conversions in datasets can be hard to get right.

Regards,
Hans
Reply With Quote
Reply

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On