BorlandTalk.com Forum Index BorlandTalk.com
Borland discussion newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Fields not available after recordset is opened

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO)
View previous topic :: View next topic  
Author Message
Mac Davis
Guest





PostPosted: Fri Nov 04, 2005 3:05 am    Post subject: Fields not available after recordset is opened Reply with quote



The following returns the correct number of records in recordcount, but I
am unable to access any of the fields.

with dm.dst_Name do begin
close;
commandtext := 'Select *, streetno, streetname from reslist, lots
where reslist.lotno = lots.lotno and lname like ' + quotedstr (stLname+'%');
commandText := commandtext + ' order by lname,fname';
open;
//ShowMessage (dm.dst_name.fieldbyname ('streetname').asstring);
statusbar1.Panels[0].Text := inttostr (recordcount);
end;


As soon as I uncomment the showMessage, I receive the following debugger
Exception Notification
---------------------------
Debugger Exception Notification
---------------------------
Project ResList.exe raised exception class EDatabaseError with message
'dst_Name: Field 'streetname' not found'.
---------------------------
Break Continue Help
---------------------------

What am I doing wrong?

Thanks,

Mac



Back to top
Mac Davis
Guest





PostPosted: Fri Nov 04, 2005 2:59 pm    Post subject: Re: Fields not available after recordset is opened Reply with quote



Does this mean that I can't have a calculated field when I'm selecting from
two tables?

-Mac-

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote

Quote:

The following returns the correct number of records in recordcount, but I
am unable to access any of the fields.

with dm.dst_Name do begin
close;
commandtext := 'Select *, streetno, streetname from reslist, lots
where reslist.lotno = lots.lotno and lname like ' + quotedstr
(stLname+'%');
commandText := commandtext + ' order by lname,fname';
open;
//ShowMessage (dm.dst_name.fieldbyname ('streetname').asstring);
statusbar1.Panels[0].Text := inttostr (recordcount);
end;


As soon as I uncomment the showMessage, I receive the following debugger
Exception Notification
---------------------------
Debugger Exception Notification
---------------------------
Project ResList.exe raised exception class EDatabaseError with message
'dst_Name: Field 'streetname' not found'.
---------------------------
Break Continue Help
---------------------------

What am I doing wrong?
You must have persistent fields defined for your dataset component that do
not
include the streetname field. When you have persistent fields defined only
those
defined fields are available.
--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]



Back to top
Bill Todd
Guest





PostPosted: Fri Nov 04, 2005 3:43 pm    Post subject: Re: Fields not available after recordset is opened Reply with quote



No. You can have calculated fields in any result set. Double click the
ADODataSet to open the fields editor and see if streetname is listed.
If there are fields listed but streetname is not among them right click
in the fields editor and add streetname.

--
Bill Todd (TeamB)
Back to top
Mac Davis
Guest





PostPosted: Sat Nov 05, 2005 4:36 pm    Post subject: Re: Fields not available after recordset is opened Reply with quote

Thanks gentelmen!

"Brian Bushay TeamB" <BBushay (AT) Nmpls (DOT) com> wrote

Quote:

Does this mean that I can't have a calculated field when I'm selecting
from
two tables?
No. But you will have to define persistent fields for each table and the
calculated fields for each table.

You can define persistent fields in code like this

var
f : TField;
i : integer;
begin
Query1.FieldDefs.Update
Query1.Close;
for i := 0 to Query1.FieldDefs.Count - 1 do
//create persistent field that do not exist
if Query1.FindField(Query1.FieldDefs[i].Name) = nil then
Query1.FieldDefs.Items[i].CreateField(Query1);
//create a calculated field
f := TStringField.Create(Query1);
f.Name := 'Query1CalcField';
f.FieldName := 'CalcField';
f.DisplayLabel := 'CalcField';
f.Calculated := True;
f.DataSet := Query1;
Query1.Open;
end;
--
Brian Bushay (TeamB)
[email]Bbushay (AT) NMPLS (DOT) com[/email]



Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> Delphi Databases (ADO) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.