Solved

How to find the changed records in dataset?

Posted on 2002-05-16
8
238 Views
Last Modified: 2010-04-04
Hello,

I'm using cached updates and in some cases there are Null values in some fields. Butt my database can not handle
these values. I would like to fill these fields with an empty string (or one space) before they are updated.
How can I see if a record in a dataset has been changed?
I would like to use something as follows:

 if MyDataSet.ChangeCount > 0 then
    MyDataSet.DisableControls;
    MyDataSet.First;
    while not MyDataSet.Eof do
     begin

//  Here I would like to know if this particular record
//  has been changed.
//  if changed then field := ' ';

       MyDataSet.Next;
     end;

Is this the proper way to do this?
I tryed OnReconcile but there I can't change my fieldvalue anymore.

Thanks,
Pascal
0
Comment
Question by:corpa
8 Comments
 
LVL 9

Expert Comment

by:ITugay
ID: 7013410
Hi corpa,

why do not let SQL server do it for you?
Declare default value for field.

------
Igor.
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7013422
or use the afterinsert or beforepost-event of the dataset
to supply the fields
0
 
LVL 9

Expert Comment

by:ginsonic
ID: 7013551
Interested
0
Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

 
LVL 1

Expert Comment

by:martin_g
ID: 7013751
How do the Null values get inserted?  It might be better to capture and change them when the record is first created or when the recored is edited by the user rather than wait for the cached update.  You can use the  record's OnValidate or OnPost event for this.

Another way is to enforce constraints on the individual fields. You would use  the field's DefaultExpression property to enter a default value such as ' ' or '0'.  You could also use the CustomExpression property to enforce a condition such as if  VALUE=NULL  then VALUE:= ' ';  These constraintsare applied when the record is posted and take precedence over server-side constraints.
0
 

Author Comment

by:corpa
ID: 7014792
Hi all,
First let me explain a little bit more about the database.
It's a real time object oriented database called InfoPlus21 by the American company AspenTech.
There are tables defined called selectorDef wich contain discrete values. These tables can be used as a lookuptable, but wont accept empty entries like space. It converts them back to a Null value. And there is my problem. I use these tables in a lookupfield in a dbgrid.
The selected value gets written in another (invisible) field from another table in that database.
So if I select the empty field in the lookuptable a Null gets into my actual field and an error occurs when I call ApplyUpdate. So my idea was before I call ApplyUpdate I go through the dataset and only look in the changed records if there's a Null in my particular field and set it to a space, because at that point and in that field the space will be accepted.
I hope I didn't lost everyone by my explanation but this is somewhat my situation.

Thanks for the cooperation so far guys,
Pascal
0
 
LVL 27

Accepted Solution

by:
kretzschmar earned 100 total points
ID: 7014813
i don't know anything about InfoPlus21,
is there no way to use a query as lookup-dataset
where these empty entries are excluded with usage of a where-clause?
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 7014821
another thing is allways to use the beforepost event of the target dataset to supply such null-fields with a value

like
procedure TForm1.Table1BeforePost(DataSet: TDataSet);

begin
if table1.fieldbyname('fieldname').IsNull then
  table1.fieldbyname('fieldname').AsString := 'Empty'; //or whatever
end;
0
 

Author Comment

by:corpa
ID: 7015707
Hi kretzschmar,

My problem is solved thanks to you.
I actually allready did use a query as lookup-dataset,
but I never got the idea to remove the Null-values in
this dataset.
So the points go to you,
Thanks again mate,
Pascal

0

Featured Post

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
How to convert wav to mp3 in delphi 9 202
Print Graphic and Text to Epson TM-T88v 12 262
how can i search if string exist in array ? 3 59
Delphi...Split view - idea? 1 70
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…

831 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question