Hi all,
in a uniquery dataset, I'm writing a sql which has a parameter like that:
Select * From Table1 Where Field1 = :P_Field1
while I am inserting a new record, I want that "Field1" field has value of "P_Field1". how could i do that?
Dataset Fields which belong to a parameter
You can use the AfterInsert event to fill the value of Field1:
Note that UniDAC can fill Field1 automatically if you link your query to the master dataset.
Code: Select all
UniQuery.FieldByName('Field1').Value := UniQuery.ParamByName('P_Field1').Value;
i think i couldnt explain my needs. I know how to assign a value from a parameter to field. what i need is, in where clause of select statement, which parameter is assigned to which field.
there are more than one parameters in where clause for different fields and there are dynamicly created parameters in code. i have the parameters by using Uniquery.Params property but which parameter is assigned to which field.
to solve my problem i made same name for parameters and fields, like that
field1 = :field1
so OnNewRecord event, I wrote that code
is there a better way? Also this code is temporary solution, if there is a condition with "OR" this code will be wrong, for ex:
where
(field1 = :field1 Or field1 = :field1_1)
second parameter must be different and my code above will cause an error because there is no field named "field1_1". in this example for field1 field, must not have a default value in OnNewRecord event.
thanks for answer.
there are more than one parameters in where clause for different fields and there are dynamicly created parameters in code. i have the parameters by using Uniquery.Params property but which parameter is assigned to which field.
to solve my problem i made same name for parameters and fields, like that
field1 = :field1
so OnNewRecord event, I wrote that code
Code: Select all
for i := 0 to UniQuery.ParamCount - 1 do
begin
UniQuery.FieldByName(UniQuery.Params[i].Name).AsVariant := UniQuery.Params[i].Value;
end;
end;
where
(field1 = :field1 Or field1 = :field1_1)
second parameter must be different and my code above will cause an error because there is no field named "field1_1". in this example for field1 field, must not have a default value in OnNewRecord event.
thanks for answer.