Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Search parameters


This question is not answered. Helpful answers available: 2. Correct answers available: 1.


Permlink Replies: 1 - Last Post: Apr 2, 2018 2:33 PM Last Post By: Steven Mitchell Threads: [ Previous | Next ]
Lawson Lutchman

Posts: 2
Registered: 5/2/18
Search parameters  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 3:46 AM
Hi Forum,

I hope this post makes sense as I am trying to create a search feature against an ADO DB that accepts an input from a combobox. I have an ADO connection, an ADOQuery and a DBGrid. I have looked at configuring parameters in the ADOQuery but cannot get the function to link to the parameter.
I have a combobox called cbsRoleFilter, I would like to display the ADOQuery results (filtered) in the grid.

My current code is.

procedure TfrmViewUsers.btnRoleSearchClick(Sender: TObject);
begin

with ADOQuery2 do begin
Close;
SQL.Clear;
dbgrid2.DataSource:= SQL.Add('select UserName,Role from FOYB_Login where Role='+
QuotedStr (cbxRoleFilter.Text));
dbgrid2.Visible:=True;
Open;

end;

end;

end.

I get..

[Error] ViewUsers.pas(79): Incompatible types: 'TDataSource' and 'Integer'

This may be the entirely incorrect approach to the problem...any suggestion will help..

Regards,
Steven Mitchell

Posts: 16
Registered: 5/8/97
Re: Search parameters  
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 2:33 PM   in response to: Lawson Lutchman in response to: Lawson Lutchman
Lawson Lutchman wrote:

Hi Forum,

I hope this post makes sense as I am trying to create a search
feature against an ADO DB that accepts an input from a combobox. I
have an ADO connection, an ADOQuery and a DBGrid. I have looked at
configuring parameters in the ADOQuery but cannot get the function to
link to the parameter. I have a combobox called cbsRoleFilter, I
would like to display the ADOQuery results (filtered) in the grid.

My current code is.

procedure TfrmViewUsers.btnRoleSearchClick(Sender: TObject);
begin

with ADOQuery2 do begin
Close;
SQL.Clear;
dbgrid2.DataSource:= SQL.Add('select UserName,Role from FOYB_Login
where Role='+ QuotedStr (cbxRoleFilter.Text));
dbgrid2.Visible:=True;
Open;

end;

end;

end.

I get..

[Error] ViewUsers.pas(79): Incompatible types: 'TDataSource' and
'Integer'

This may be the entirely incorrect approach to the problem...any
suggestion will help..

Regards,

You do not mention a TDataSource component (eg DataSource1) that should
be connected to the dbgrid2.DataSource property. The ADOQuery2 should
be connected to the DataSource1.Dataset property.

Also for clarity I recommend you do not use 'with' statements.

DataSource1.Dataset := ADOQuery2;
dbgrid2.DataSource := DataSource1;
ADOQuery2.Close;
ADOQuery2.SQL.Text := 'select UserName,Role from FOYB_Login where
Role=' + QuotedStr (cbxRoleFilter.Text));
dbgrid2.Visible := True;
ADOQuery2.Open;

HTH.
Steve
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02