Solved

How to find the changed records in dataset?

Posted on 2002-05-16
8
237 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Simple Delphi Question 9 83
Internet Explorer View Settings Question 15 105
how to center only a line in richedit? 4 52
creating threads in delphi 1 81
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
With Secure Portal Encryption, the recipient is sent a link to their email address directing them to the email laundry delivery page. From there, the recipient will be required to enter a user name and password to enter the page. Once the recipient …

930 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now