Solved

How to find the changed records in dataset?

Posted on 2002-05-16
8
235 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
Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

 

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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

707 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

17 Experts available now in Live!

Get 1:1 Help Now