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 

Working with Query results

 
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (SQL Servers)
View previous topic :: View next topic  
Author Message
Anthony
Guest





PostPosted: Tue Apr 11, 2006 1:03 am    Post subject: Working with Query results Reply with quote



I have an Access Database with several tables configured and using
TQuery components to select the records to work with. I have the
queries working fine and obtain the records I need, but my issue comes
when I try to work the data of an individual record. Not all of the
records have all of the fields populated and this seems to be causing
Builder some problems. I would like to do the following:
Label1->Caption = TQuery1->FieldValues["Field1"]->AsString

but if the result is empty it crashes. What I have had to do is check
each item of each record before I use like this:

if (TQuery->FieldValues["Field1"] != Variant.ChangeType(varNull))
{ Label1->Caption = TQuery1->FieldValues["Field1"]->AsString }

Is there an easier or another way of doing this?

Anthony
Back to top
Pedro Fehlauer
Guest





PostPosted: Wed Jul 05, 2006 7:54 pm    Post subject: Re: Working with Query results Reply with quote



That's strange, it doesn't happen to me. If a NULL field is assing to a
string type, it should shield an empty string.

Are you using ODBC? Maybe some setting in the datalink...

Pedro


<Anthony> escribió en el mensaje
news:ptvl32td10qs6tbcu4l7p4gtrjekl9f1kd (AT) 4ax (DOT) com...
Quote:

I have an Access Database with several tables configured and using
TQuery components to select the records to work with. I have the
queries working fine and obtain the records I need, but my issue comes
when I try to work the data of an individual record. Not all of the
records have all of the fields populated and this seems to be causing
Builder some problems. I would like to do the following:
Label1->Caption = TQuery1->FieldValues["Field1"]->AsString

but if the result is empty it crashes. What I have had to do is check
each item of each record before I use like this:

if (TQuery->FieldValues["Field1"] != Variant.ChangeType(varNull))
{ Label1->Caption = TQuery1->FieldValues["Field1"]->AsString }

Is there an easier or another way of doing this?

Anthony
Back to top
Anthony
Guest





PostPosted: Thu Jul 06, 2006 6:03 am    Post subject: Re: Working with Query results Reply with quote



I'm not sure on the ODBC. But I don't think so. I am using Borland 5
and MSAccess database through TQuery components.

Are you using TQuery1->FieldValue["Field1"]->AsString or are you using
TQuery1->FieldByName("Field1")->AsString?

I have read many places that FieldValues is the preferred method, but
also have found the overhead required as I described below. I have
avoided much of the overhead by using FieldByName.

Am I going in the right direction? I hope so since I have just
started alpha testing on the application.

Anthony

On Wed, 5 Jul 2006 09:54:38 -0500, "Pedro Fehlauer"
<info@sistemas-especificos.com> wrote:

Quote:
That's strange, it doesn't happen to me. If a NULL field is assing to a
string type, it should shield an empty string.

Are you using ODBC? Maybe some setting in the datalink...

Pedro


Anthony> escribió en el mensaje
news:ptvl32td10qs6tbcu4l7p4gtrjekl9f1kd (AT) 4ax (DOT) com...

I have an Access Database with several tables configured and using
TQuery components to select the records to work with. I have the
queries working fine and obtain the records I need, but my issue comes
when I try to work the data of an individual record. Not all of the
records have all of the fields populated and this seems to be causing
Builder some problems. I would like to do the following:
Label1->Caption = TQuery1->FieldValues["Field1"]->AsString

but if the result is empty it crashes. What I have had to do is check
each item of each record before I use like this:

if (TQuery->FieldValues["Field1"] != Variant.ChangeType(varNull))
{ Label1->Caption = TQuery1->FieldValues["Field1"]->AsString }

Is there an easier or another way of doing this?

Anthony
Back to top
Display posts from previous:   
Post new topic   Reply to topic    BorlandTalk.com Forum Index -> C++ Builder Databases (SQL Servers) 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.