Results 1 to 2 of 2
  1. #1
    Join Date
    May 2009
    Posts
    1

    Unanswered: 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);

  2. #2
    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •