Page 1 of 1
Dataset Fields which belong to a parameter
Posted: Wed 09 Dec 2009 09:55
by flyy
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?
Posted: Thu 10 Dec 2009 09:01
by Plash
You can use the AfterInsert event to fill the value of Field1:
Code: Select all
UniQuery.FieldByName('Field1').Value := UniQuery.ParamByName('P_Field1').Value;
Note that UniDAC can fill Field1 automatically if you link your query to the master dataset.
Posted: Thu 10 Dec 2009 21:57
by flyy
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
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;
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.
Posted: Mon 14 Dec 2009 08:43
by Plash
There is no better way for copying values from parameters to fields. You need to create special logic in your procedure to handle OR conditions.
Posted: Mon 14 Dec 2009 11:16
by flyy
thanks for your help @plash