Query Exception - field data beyond Eof

gtalpers

Member
Greetings!

Sometimes when executing a query using the TOracleQuery I get an exception raised and the message is 'You cannot access field data beyond Eof'. The query seems to work OK, but I would to know what this exception means, and why it is happening. Can anyone help???

TIA - Gary
 
You are accessing field data (TOracleQuery.Field, FieldAs..., FieldIsNull, ...) when Eof = True. There is no data, and this results in the exception.

------------------
Marco Kalter
Allround Automations
 
Marco, thanks for your reply - but let me make sure I understand. Consider the following code:

function TQCWebMod.GetUserName(const UserID: string): string;
begin
try
OracleQuery1.SetVariable('THEUSER', UserID);
OracleQuery1.Execute;
Result := OracleQuery1.Field('USER_NAME');
except
on E: Exception do begin
ShowMessage(E.Message);
end;
end;
end;

Are you saying that if the name field is blank an Exception will be raised? If so, is there a way to avoid this? I was assuming that this function would just return a blank string '' if nothing was in the USER_NAME field.

Thanks again for your help!

Gary
 
No, if the name is blank the result will be an empty string. If the query returns 0 rows you will get the exception. Your code should be something like this:
Code:
OracleQuery1.Execute;
if OracleQuery1.Eof then
  {do something in case of 0 rows}
else
  Result := OracleQuery1.Field('USER_NAME');

------------------
Marco Kalter
Allround Automations
 
Back
Top