Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 5 of 5 total
Thread saving data
Tue, Sep 2 2014 2:56 PMPermanent Link

Harry de Boer

Hi,

I created a dataset (from a dbisam table) with the datamanager. Created a grid and when I load the data, it is shown in the grid. Then I put the grid in Edit (update) mode, and change a few values in the grid. Then I want to save the data. However with the code below the data is nor really saved to the dbisam table. Am I missing something?

Regards, Harry

procedure TForm1.btnFetchClick(Sender: TObject);
begin
  Database.Load(dbisamtest1); //load the data from a dbisam table (OK)
end;

procedure TForm1.btnEditClick(Sender: TObject);
begin
 dbisamtest1.Update; //put in Editmode (now you can edit the grid) (OK I guess, no errors)
end;

procedure TForm1.btnSaveClick(Sender: TObject);
begin
  dbisamtest1.Save; // saves the changes (no errors but does not work -not actually saving to the table)
end;
Tue, Sep 2 2014 3:19 PMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 9/2/2014 2:56 PM, Harry de Boer wrote:
> Hi,
>
> I created a dataset (from a dbisam table) with the datamanager. Created a grid and when I load the data, it is shown in the grid. Then I put the grid in Edit (update) mode, and change a few values in the grid. Then I want to save the data. However with the code below the data is nor really saved to the dbisam table. Am I missing something?
See

http://www.elevatesoft.com/manual?action=viewtopic&id=ewb1&topic=Transactions

Raul
Tue, Sep 2 2014 4:08 PMPermanent Link

Harry de Boer

>>http://www.elevatesoft.com/manual?action=viewtopic&id=ewb1&topic=Transactions

Hi Raul,

I missed indeed that a Transaction was mandatoty for actually saving the data to the physical table. Thanks for pointing it out. However I read the article a couple of times and thought that using a Database.StarTransaction and Database.Commit would solve it. However I keep getting a 'row not found' error.

Q
-Do I need the Update statement for putting the grid in Edit mode?
-Where in my code do I put the StartTransaction and the Commit (tried putting it on:

procedure TForm1.btnFetchClick(Sender: TObject);
begin
 //Tried StartTransaction here
 Database.Load(dbisamtest1);
end;

procedure TForm1.btnEditClick(Sender: TObject);
begin
 //tried  StartTransaction here
dbisamtest1.Update;
end;

procedure TForm1.btnSaveClick(Sender: TObject);
begin
 dbisamtest1.Save;
 //Tried Commit here
end;

Regards, Harry
Tue, Sep 2 2014 4:37 PMPermanent Link

Raul

Globestar Systems

Team Elevate Team Elevate

On 9/2/2014 4:08 PM, Harry de Boer wrote:

Harry,

> I missed indeed that a Transaction was mandatoty for actually saving the data to the physical table. Thanks for pointing it out. However I read the article a couple of times and thought that using a Database.StarTransaction and Database.Commit would solve it. However I keep getting a 'row not found' error.

I will assume you're using EWB web server here and not your own backend.

if you see something along the lines of "cannot find the row for
updating" then usually it's caused by not having a primary key defined
in the original table. \

Since EWB is async (it downloads data, you modify it and then it uploads
it again) it needs a unique way of matching it up later and primary key
is needed.

The other reason can be that the primary key exists but cannot be found
- make sure you're primary key is not something user can edit (i.e.
username, part #, etc). I'd suggest you add an autoinc integer and such
and see if that makes it work.


> -Do I need the Update statement for putting the grid in Edit mode?

You need to call update to edit an existing. You would need to call
Insert to add new one for example.


> -Where in my code do I put the StartTransaction and the Commit (tried putting it on:

It really depends on your app design.

You can definitely wrap every edit with a transaction (wasteful but
should work). Putting it in btnEditClick and btnSaveClick should work yes.

Later on you can decide to allow multiple edits in a single transaction
- 1st edit/insert puts the DS into transaction (you can use
BeforeUpdate/BeforeInsert events here) and then you need a way to then
commit - either based on user feedback on when they start navigating to
another section of you app (another form for example).

Raul



Wed, Sep 3 2014 5:01 AMPermanent Link

Harry de Boer

Hi Raul,

adding a PK did the trick. Thanks.

Regards, Harry
Image