Solved

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

Posted on 2004-10-17
16
894 Views
Last Modified: 2010-04-05
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...
0
Comment
Question by:mece
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 7
  • 4
  • 2
  • +3
16 Comments
 
LVL 13

Expert Comment

by:BlackTigerX
ID: 12334459
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
 
LVL 12

Accepted Solution

by:
esoftbg earned 125 total points
ID: 12334477
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
 
LVL 17

Expert Comment

by:mokule
ID: 12334522
Hi,
Haven't You got by chance not Updated Delphi 5? It has a bug.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 12

Expert Comment

by:Ivanov_G
ID: 12334822
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
 

Author Comment

by:mece
ID: 12338894
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
 
LVL 17

Expert Comment

by:mokule
ID: 12339454

If this is a case I was writing about You should update Delphi.
0
 

Author Comment

by:mece
ID: 12340106
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
 
LVL 12

Expert Comment

by:esoftbg
ID: 12340239
didn't you try my code ?
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12340399
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
 

Author Comment

by:mece
ID: 12340705
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
 
LVL 3

Expert Comment

by:danielluyo
ID: 12340834
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
 
LVL 12

Expert Comment

by:esoftbg
ID: 12340919
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
 
LVL 12

Expert Comment

by:esoftbg
ID: 12340943
danielluyo, I think mece does update of the current record in the dsSSet .... That's all.
0
 
LVL 12

Expert Comment

by:esoftbg
ID: 12351402
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
 
LVL 12

Expert Comment

by:esoftbg
ID: 12351463
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
 

Author Comment

by:mece
ID: 12356107
hi esoftbg

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

Thanx for help

MeCeX
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
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…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

734 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