I have a table with fields "field_1, field_2, field_3". Primary index is "field_1;field_2"
Unitable1.Options.StrictUpdate := False;
Unitable1.IndexFieldNames := "field_1;field_2"
Unitable1.KeyFields := "field_1"
For example I have 5 records in the table of field_1 column has values "x", field_2 values are different.
When I change the value of any cell in field_3 column with field_1 "x" value, all the cells in field_3 values changes.
When I delete one of the records that field_1 value is "x", all records is deleted too where field_1 value is "x".
When I try to change field_2 value with field_1 "x", it gives "Duplicate key" error.
KeyFields Problem
Re: KeyFields Problem
You need to set Unitable1.KeyFields := 'Field_1;Field_2'
Setting the KeyFields property is telling UniTable which field is in fact the primary key for its DML.
So you are sending
Update table set fields..
WHERE
FIELD_1 = value
Setting the KeyFields property is telling UniTable which field is in fact the primary key for its DML.
So you are sending
Update table set fields..
WHERE
FIELD_1 = value
-
- Posts: 2
- Joined: Wed 02 Aug 2017 09:20
Re: KeyFields Problem
I need to write Field_1 to "Keyfield's" in order to be able to make search according to Field_1 area by using FindKey.
I can perform search with "Locate" too, but in the project which I'm converting from Paradox to SQL, there are lots of FindKey commands which are used that way.
Is there anything else I can do except using Locate Command?
I can perform search with "Locate" too, but in the project which I'm converting from Paradox to SQL, there are lots of FindKey commands which are used that way.
Is there anything else I can do except using Locate Command?
Re: KeyFields Problem
One of the variants to solve this task can be the use of custom UPDATE/DELETE SQL queries. For example, if necessary
And set the generated SQL query to the TUniTable.SQLUpdate.Text property:
For more information about SQLUpdate in our online documentation:
https://www.devart.com/unidac/docs/?dev ... update.htm
Then you can compose such a SQL query to edit the data:yucelkarapinar wrote: When I change the value of any cell in field_3 column with field_1 "x" value, all the cells in field_3 values changes.
Code: Select all
IF (:field_3 <> :Old_field_3) AND (:field_1 = 'x')
UPDATE table_11 SET field_3 = :field_3
Code: Select all
Unitable1.Options.StrictUpdate := False;
UniTable1.SQLUpdate.Text := ' IF (:field_3 <> :Old_field_3) AND (:field_1 = ''x'') ' +
' UPDATE table_11 SET field_3 = :field_3';
Unitable1.Open;
https://www.devart.com/unidac/docs/?dev ... update.htm