How can i append record to TAdoQuery without clearing its fields?

548 views Asked by At

I am using TAdoQuery with BatchOptimistic lock type. If the select command has some fields that are calculated on database server the returned fields has property ReadOnly = true, so i must change them to false so i can modify them in my query.

I am actually never attempting to post to database, but i must use TAdoQuery.

Its all good to the point I append or insert some record, set its fields, and then call for example TAdoQuery.Last, Next or First.. The appended records fields change to null. Please, is there a way that these records could stay as they were?

I am attaching a simple code here, where the problem is presented:

      // .. lockType = Batchoptimistic so TAdoQuery.first or TAdoQuery.last do NOT post do database
      ADOQuery1.LockType := ltBatchOptimistic;
      ADOQuery1.SQL.Text := 'SELECT 10 AS id, 20 AS sid ';
      ADOQuery1.Open;
    
      // .. readOnly = false so i can modify these two fields in appended record
      ADOQuery1.FieldByName('id').ReadOnly := false;
      ADOQuery1.FieldByName('sid').ReadOnly := false;
      ADOQuery1.Append;
    
      ADOQuery1.FieldByName('id').AsInteger := 5;
      ADOQuery1.FieldByName('sId').AsInteger := 5;
    
      // if use last, first  etc. the appended record fields will change to 0 (null)
      ADOQuery1.Last;
0

There are 0 answers