-1

I recently made a very basic "Client" DBGrid that shows info from an Access database (connected made with an ADOQuery, DataSource,ADOConnection and ADOTable). I would like to know if there is a way that I can search for spesific records (like just a name) and add the "Payment" table of that record together and show it in a Memo when I press a button.

I have searched for help far and wide and I couldn't find anything logical, it may be a stupid question to someone who is an expert but I find this very difficult, so please be kind.

L. Blue
  • 1
  • 3
  • 1
    You don't search in the DBGrid. You search in the table or query connected to the grid, using that table or query's Locate method. I have no idea what you mean by *add the "Payment" table of that record together and show it in a Memo*. The help file has tutorials on how to search for data in a dataset. Have you looked there? – Ken White Mar 02 '16 at 18:46
  • What @KenWhite said. Plus: Which of your datasets is connected to the grid? And is your AdoQuery selecting records from a single table or joined tables? – MartynA Mar 02 '16 at 18:47
  • I mean which ever amounts that are displayed for the person that I searched for should be added together (Like payment+payment) these are in the dbgrid. And when I press a button it looks at what I searched and displays (however, in a memo or showmessage or ecs.) that this person has paid an amount in total. I don't know how to do that, I've searched for help but they said I needed a datamodule which makes this far more complicated for a simple task. – L. Blue Mar 03 '16 at 17:44
  • Please [edit] your question to provide more details. You've indicated that you're using both an ADOQuery and and ADOTable ; which is connected to your grid, and which one contains the data you want to sum? And for the one *not* attached to your grid, what are you currently using it for? It's difficult to help you when you don't provide any useful information. Read your question, keeping in mind that we know absolutely nothing about your problem other than what you provide to us. Could you answer a question based on the (lack of) information you've provided? – Ken White Mar 03 '16 at 19:38

2 Answers2

1

I did not understand your question very well, I ask you to identify your problem and explain precisely to make it easier on us to help you.

-To search for a customer name in the table is as follows :

If Not ADOTable1.Locate('Name',Edit1.Text,[]) then
   MessageDlg('The customer does not exist !',mtInformation,[mbOK],0);

Locate Options : loCaseInsensitive,loPartialKey .

You can also search by ADOQuery Here's an example:

ADOQuery1.Close;
ADOQuery1.SQL.Text := 'Select * From YourTable Where Name ='+QuotedStr(Edit1.Text);
ADOQuery1.Open;

Or you can use ADOQuery Parameters Like this:

ADOQuery1.Close;
ADOQuery1.Parameters.ParamByName('Term').Value:=Edit1.Text;
ADOQuery1.SQL.Text := 'Select * From YourTable Where Name=:Term';
ADOQuery1.Open;

Good Luck.

Ilyes
  • 14,640
  • 4
  • 29
  • 55
0

Search should be done via ADOTable methods Locate(). If you use ADOQuery you can rewrite SQL for search as well (don't forget to protect against injections and use parameters if possible) If you need to display some extra info while pressing a button - obtain needed key value from AdoTable and apply as parameter for dependent query