Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

while Loop problem

Status
Not open for further replies.

Larree

Programmer
Dec 31, 2002
20
SG
Hi all,

I encountered the following problem. Code looks ok but and no errors when I compile. But when I activate the function an error is generated saying that attempt to update or delete failed. The code is as follows:

Timing1 = CTime::GetCurrentTime();

if( m_pCapturedResults.IsOpen() == FALSE )
{
m_pCapturedResults.Open();
}

m_pCapturedResults.MoveFirst();
m_pCapturedResults.Edit();

while(!m_pCapturedResults.IsEOF())
{
m_pCapturedResults.m_Time_Started =
Timing1.Format("%H:%M:%S");

m_pCapturedResults.Update();
m_pCapturedResults.Requery();

m_pCapturedResults.MoveNext();

}

m_pCapturedResults.Close();

Please advice on this coz it seems that if I remove the while loop, the update is possible for the first record in my database but when I add the while loop, the update seems impossible even though teh first record will still be updated. Thanks
 
The sequence
m_pCapturedResults.Requery();
m_pCapturedResults.MoveNext();
looks suspicious. Doesn't Requery reset current record pointer to the initial state?
 
Yeah i think mingis is right ..I encountered and solved the same sort of problem some times back. I think only these 2 lines are enough , no need of 'm_pCapturedResults.MoveNext()'
These 2 are enough
m_pCapturedResults.Update();
m_pCapturedResults.Requery();

and i don't think any need of while statement as pointer will be on current record
 
Thanks....I guess that is the problem. However I need to keep the while loop coz I want the same data to be in every entry of my database. However, even after removin the MoveNext() command, I still encounter the same error message " attempt to update or delete failed." Compiling generates no error again. Please advice on this.... Thanks
 
The problem is with the edit().

You need to put this inside the while loop.

For every update statement you require and edit() or addnew().

As you have the edit() outside the while loop the code runs once fine and then fails as you try to update without and edit.

Hope this helps.
 
I agree with DazzG about Edit.
Also, my suspicion was on Requery, not MoveNext.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top