Board index » delphi » Write back after value changed using SQL

Write back after value changed using SQL

Dear all,

I use SQL statement to operate a paradox table in D4, after using statement
'SELECT * FROM TABLE1 WHERE .......' to fetch satisfied records,

1. How do I modify some fields' values of those records?
2. Afterwards, how do I write them back(primary keys not changed in those
action)?

Any help is appreciated.

--
Best regards,
Lurc

 

Re:Write back after value changed using SQL


Quote
On Wed, 9 Feb 2000 14:43:11 +0800, "Lurc" <lurc...@hotmail.com> wrote:
>I use SQL statement to operate a paradox table in D4, after using statement
>'SELECT * FROM TABLE1 WHERE .......' to fetch satisfied records,

>1. How do I modify some fields' values of those records?
>2. Afterwards, how do I write them back(primary keys not changed in those
>action)?

First thing to try is to set RequestLive to True.  Depending on your
query a live cursor will be granted or not; check the CanModify
property to find out if you really have a live cursor.  For a live
cursor, you can update the values just like for a TTable.

If a live cursor cannot be granted, you need to set CachedUpdates to
True.  Again you can update the values just like with a regular
TTable, but since all changes are cached you now have to provide
something extra to update the physical table.  For Paradox tables, I
would suggest writing an OnUpdateRecord event handler that uses a
regular TTable to perform the updates.

HTH,

Jan

Re:Write back after value changed using SQL


Quote
> Lurc wrote:

> I use SQL statement to operate a paradox table in D4, after using
> statement
> 'SELECT * FROM TABLE1 WHERE .......' to fetch satisfied records,

> 1. How do I modify some fields' values of those records?
> 2. Afterwards, how do I write them back(primary keys not changed in  > those action)?

To get a live (i.e. modifiable) result returned, set Query.RequestLive
to true. Note that a live result set is not guaranteed, depending on the
SELECT statement. You can test for it with Query.CanModify.
________
Andreas

Re:Write back after value changed using SQL


Quote
Lurc wrote:
> Dear all,

> I use SQL statement to operate a paradox table in D4, after using statement
> 'SELECT * FROM TABLE1 WHERE .......' to fetch satisfied records,

> 1. How do I modify some fields' values of those records?
> 2. Afterwards, how do I write them back(primary keys not changed in those
> action)?

Jan Sprenger described how to get a live result set, which is necessary to
edit the data in the result set after executing that SELECT statement. This is
to (briefly) describe how to do the editing.

If you would be using visual data controls to edit the data, do this by using
a TDataSource as the conduit between result set and data editing controls. Add
a TDataSource to the form and set its DataSet property to the TQuery. This can
be done at design-time using the Object Inspector. It can also be done
programmatically at runtime as per the example below:

  DataSource1.DataSet := Query1;

Then add your data editing controls to the form, such as a TDBGrid. Set the
DataSource property of the editing controls to the TDataSource. If the control
is a single-field control (like TDBEdit or TBDMemo), set its DataField
property to the name of the field. Again, this can be done at design-time or
at runtime.

  DBEdit1.DataSource := DataSource1;
  DBEdit1.DataField := 'LastName';

If, instead, you would be changing the data programmatically without using any
visual data controls, use methods of the dataset to initiate and fianlize the
edit process. For instance, use the Edit method to start editing an existing
record. Use the Fields property or FieldByName method of the dataset component
to access one field. Use properties of TField such as AsString and AsInteger
to set or get field values through the TField reference provided by Fields and
FieldByName. Call the Post method of the dataset to finalize the editing
operation.

  with Table1 do begin
    Edit;
    FieldByName('LastName').AsString := 'Smith';
    Post;
  end;

Re:Write back after value changed using SQL


Set the RequestLive property of the query component to True. See RequestLive
in the on-line helpf for restrictions on the syntax of the query.

--
Bill

Bill Todd (TeamB)
(TeamB cannot respond to questions received via email)

Other Threads