TDBGrid is used for viewing the visible records in a dataset linked with it (through the DataSource property). So if you want to view certain records (through filters), you have to set the filter in the dataset control (TADOQuery or else : TClientDataSet, TFDMemTable, TFDQuery, ...).
For setting the filter in Delphi datasets, you have to write an SQL filtering statement in the Filter
property, like the following code :
begin
ADOQuery1.Filtered := False;
ADOQuery1.Filter := 'State = ' + QuotedStr('CA') + ' OR ' +
'State = ' + QuotedStr('CA');
ADOQuery1.Filtered := True;
end;
You can check this links for more details about setting filters :
On the other hand, parameters in ADODB datasets are variables that you can incorporate in a parameterized SQL statement (like formatting strings in the function Format()
).
These parameters are TParameter
objects with values that can be assigned in design-time or run-time then they will be included in the statement by replacing the corresponding parameter.
Parameters in the SQL statement start with :
For example in the following statement SELECT * FROM customer WHERE customer_id = :AnId;
The :AnId
string will be replaced with the value of the parameter named AnId
.
You first have to set a parameterized SQL statement in the TADOQuery, then you create the parameter by looking up from the statement for a parameter with the same name, and assign a type and a value for your parameter so as it will be formatted in the statement before execution.
Like this code :
var
Param : TParameter;
begin
ADOQuery1.SQL.Add(SQLStr);
Param := ADOQuery.Parameters.ParamByName('AnId');
Param.DataType := ftInteger;
Param.Value := 1;
end;
You can check this code example for using parameters in queries in TADOQuery :
https://docwiki.embarcadero.com/CodeExamples/Alexandria/en/ADOQuery_(Delphi)
And here is more informations about using parameters in queries :
https://docwiki.embarcadero.com/RADStudio/Alexandria/en/Using_Parameters_in_Queries