Board index » delphi » Setting value of database field ?

Setting value of database field ?

Some how I'm missing it!  Coming from Clipper I used Field->fieldname :=
value, amongst a couple other methods.  After a couple days and four
different ref books, I don't seem to find how to write the value of a field
to the table.  I know it's staring me right in the face.  Here's what I have
so far.  I have a TTable and TDataSource component that point to the table
on a form.  Only a few of the fields are being edited on the form.  I have a
'new' button with an OnClick method which places the table in Append by
calling the Table1.Append method.  I have a save button with an OnClick
method.  Here I wish to not only post the data in the fields edited on the
form, but I also wish to write default values to the other fields in that
record.  I keep coming back to the FieldByName() method.  But when I use the
Table1.Post method, I get an "EDBExecptionError with message 'key

Details: (Paradox 7)

requestdate    D
active         L
order_qty2    S

code snipet.......

Table1.FieldByName('REQUESTDATE').AsDateTime := date;
Table1.FieldByName('ACTIVE').AsBoolean := True;
Table1.FieldByName('ORDER_QTY1').AsInteger := 5;

if Table1.State = dsEdit
if Table1.State = dsInsert

I've commented out each line individually and each statement seem to cause a
key violation.  Any help putting me in the right direction would be most



Re:Setting value of database field ?

A key violation error message occurs when you try to post a record whose
primary key value is identical to the primary key of a record that already
exists or which has a value in the field(s) covered by a unique index that
is identical to the value in an existing record.

If you want to put default values into fields immediately before posting put
your code in the TTable's BeforePost event handler, not the OnClick handler
for your button.

(TeamB cannot answer questions received via email)

Other Threads