TAdoDataSet "Either bof or eof is true, ..." Error! Why ? How to solve ?

Hi to all,

When below code executes in my program,
*************************
dsSine.Filter := 'SineID=NULL';
dsSine.Filtered := true;

dsSine.First;
for i := 1 to dsSine.RecordCount do
  dsSSet.Edit;
  dsSSet['SS'] := dsSSet['SS'] - dsSine['Mict'];
  dsSSet.Post;
end;

dsSine.Filtered := false;
********************
it gives error "Either BOF or EOF is true or the current record has been deleted,Requested operation requires a current record" at the last line (posting).I'm using delphi 7, with installed update. I recompile, rebuild my code after update but nothing changes. I search internet, found some solutions but all for delphi 5 and says "update your delphi".

When i put "try except" code into the loop, it does not post first and last changes to dataset.

(Database is key indexed with autoincrement number field.)

Any ideas ? I need a solution...

Thanx...
meceAsked:
Who is Participating?
 
esoftbgCommented:
Try this:

  dsSine.Filter := 'SineID=NULL';
  dsSine.Filtered := true;
  try
    if (dsSine.RecordCount>0) then
    begin
      dsSine.First;
      while not dsSine.EOF do
      begin
        dsSSet.Edit;
        dsSSet['SS'] := dsSSet['SS'] - dsSine['Mict'];
        dsSSet.Post;
        dsSine.Next;
      end;
    end;
  finally
    dsSine.Filtered := false;
  end;
0
 
BlackTigerXCommented:
try something like:

dsSine.Filter := 'SineID=NULL';
dsSine.Filtered := true;

dsSine.First;
while not (dsSine.EOF) do
  dsSSet.Edit;
  dsSSet['SS'] := dsSSet['SS'] - dsSine['Mict'];
  dsSSet.Next //this should automatically call the Post method
end;

dsSine.Filtered := false;
0
 
mokuleCommented:
Hi,
Haven't You got by chance not Updated Delphi 5? It has a bug.
0
Cloud Class® Course: CompTIA Cloud+

The CompTIA Cloud+ Basic training course will teach you about cloud concepts and models, data storage, networking, and network infrastructure.

 
Ivanov_GCommented:
Update your MDAC components to version 2.8 from Microsoft's site. If you are using Delphi 7 with update to 7.1 this should help:
http://www.microsoft.com/downloads/details.aspx?FamilyID=6c050fe3-c795-4b7d-b037-185d0506396c&displaylang=en
0
 
meceAuthor Commented:
I update mdac to 2.8 but it gives error again.

i tried  BlackTigerX's code, it didnt work. I will try esoftbg's code.
0
 
mokuleCommented:

If this is a case I was writing about You should update Delphi.
0
 
meceAuthor Commented:
how can i update delphi ? mokule

I installed delphi 7 update 1 pack. I updated mdac 2.8.
I read about updating delphi 5 at internet but i use delphi 7. What can i do ? This is a bug and i dont know how to fix it
0
 
esoftbgCommented:
didn't you try my code ?
0
 
esoftbgCommented:
mece's code is obviously a wrong one:
//........
dsSine.First;
for i := 1 to dsSine.RecordCount do // THIS LOOP AFFECTS ONLY NEXT ROW AND YOU HAVE MANY TIMES dsSSet.Edit; ????
  dsSSet.Edit;
  dsSSet['SS'] := dsSSet['SS'] - dsSine['Mict'];
  dsSSet.Post;
end;


BlackTigerX,s code is obviously a wrong one:
//........
while not (dsSine.EOF) do              // THIS LOOP AFFECTS ONLY NEXT ROW AND YOU HAVE MANY TIMES dsSSet.Edit; ????
  dsSSet.Edit;
  dsSSet['SS'] := dsSSet['SS'] - dsSine['Mict'];
  dsSSet.Next //this should automatically call the Post method
end;

Only my code is a correct one ....
0
 
meceAuthor Commented:
I^'m tring your code but something interesting here that when i run it, only one dataset is updated and at the second loop (next is called), eof becomes true. But i have 5 records in dataset !!!
0
 
danielluyoCommented:
toy have 2 dataset dsSET and dsSINE.
You are looping  dsSine but updating dsSET?? is that correct??

dsSine and dsSET could have a different number of records, after the filter is applied maybe there is something wrong with the logic
0
 
esoftbgCommented:
You may use a ADOqueryCount to get the correct RecordCount by next code:

  dsSine.Filter := 'SineID=NULL';
  dsSine.Filtered := true;
  try
    ADOqueryCount.Active := False;
    ADOqueryCount.SQL.Text := ' SELECT COUNT(*) as FILTERED_CONUT FROM Sine WHERE SineID=NULL';
    ADOqueryCount.Active := True;
    if (ADOqueryCount.FieldByName('FILTERED_CONUT').AsInteger>0) then
    begin
      dsSine.First;
      while not dsSine.EOF do
      begin
        dsSSet.Edit;
        dsSSet['SS'] := dsSSet['SS'] - dsSine['Mict'];
        dsSSet.Post;
        dsSine.Next;
      end;
    end;
  finally
    dsSine.Filtered := False;
  end;
0
 
esoftbgCommented:
danielluyo, I think mece does update of the current record in the dsSSet .... That's all.
0
 
esoftbgCommented:
Hi mece,
I am trying to understand this senetnce:
> I^'m tring your code but something interesting here that when i run it, only one dataset is updated and at the second loop (next is called), eof becomes true. But i have 5 records in dataset !!!

Only one dataset (dsSSet) is updated because:
        dsSSet.Edit;
        //........;
        dsSSet.Post;
The loop is for dsSine, but the update is for dsSSet.

May be
  dsSine.Filter := 'SineID=NULL';
reduces the count of records from 5 to 2 that satisfy the condition 'SineID=NULL';
i.e. only into 2 records the field SineID is NULL
0
 
esoftbgCommented:
There is no loop about dsSSet so my code updates the current record of dsSSet. Only you know which is this record, i.e. on every run of above code, the current record may be different or same: it depends on the user of application ....
May be your code in the question is totally wrong and I can not understand it correctly ?
0
 
meceAuthor Commented:
hi esoftbg

it gives same error at the last loop but at this time, it saves changes to database

Thanx for help

MeCeX
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.