Watch, Follow, &
Connect with Us

Please visit our new home
community.embarcadero.com.


Welcome, Guest
Guest Settings
Help

Thread: Search parameters



Permlink Replies: 1 - Last Post: Apr 2, 2018 1:04 AM Last Post By: Jeff Overcash (... 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 12:26 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,
Jeff Overcash (...

Posts: 1,529
Registered: 9/23/99
Re: Search parameters
Click to report abuse...   Click to reply to this thread Reply
  Posted: Apr 2, 2018 1:04 AM   in response to: Lawson Lutchman in response to: Lawson Lutchman
On 4/2/2018 3:26 AM, 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,

This forums is about the codecentral repository. You should be asking this in
the ADO newsgroup.

That being said SQL.ADD() returns the index of the newly added line. You want
ot set the DataSource to ADOQuery2.

Get out of the habit of using with, it leads to silly errors like this or can
introduce very hard to track down semantic errors. Don't be afraid to type and
make your code clearer.

--
Jeff Overcash (TeamB)
(Please do not email me directly unless asked. Thank You)
Learning is finding out what you already know. Doing is demonstrating that you
know it. Teaching is reminding others that they know it as well as you. We are
all leaners, doers, teachers. (R Bach)
Legend
Helpful Answer (5 pts)
Correct Answer (10 pts)

Server Response from: ETNAJIVE02