Board index » delphi » Not sure what I'm doing :)

Not sure what I'm doing :)

I'm trying to set some variables using:

MyVariable := qry.FieldValues['myfieldvalue'];

However, if 'myfieldvalue' is NULL I get an exception...is there a way
around this other than in the SQL statement itself. My goal is that even if
the value is NULL I can replace it with my own text (i.e. Not Available). I
tried an if statement but that too raised an exception. All I know to do at
this point is maybe a try but I don't think that would work either.

Help!! Thanks in advance!

-Brent

 

Re:Not sure what I'm doing :)


Use qry.FieldByName('yourfieldname').AsString
or AsInteger, or AsFloat, etc...
You can also check if the field is null:
if qry.FieldByName('yourfieldname').IsNull then
    ...
bye

Quote
Brent wrote:
> I'm trying to set some variables using:

> MyVariable := qry.FieldValues['myfieldvalue'];

> However, if 'myfieldvalue' is NULL I get an exception...is there a way
> around this other than in the SQL statement itself. My goal is that even if
> the value is NULL I can replace it with my own text (i.e. Not Available). I
> tried an if statement but that too raised an exception. All I know to do at
> this point is maybe a try but I don't think that would work either.

> Help!! Thanks in advance!

> -Brent

--
Guillermo Casta?o Acevedo
Gerente de Sistemas - Grupo Millennium Ltda
Guiller...@GrupoMillennium.com
www.GrupoMillennium.com

Re:Not sure what I'm doing :)


Why not use the 'try' ? That'll work

Jaap Versteegh

Quote
> I'm trying to set some variables using:

> MyVariable := qry.FieldValues['myfieldvalue'];

> However, if 'myfieldvalue' is NULL I get an exception...is there a way
> around this other than in the SQL statement itself. My goal is that even
if
> the value is NULL I can replace it with my own text (i.e. Not Available).
I
> tried an if statement but that too raised an exception. All I know to do
at
> this point is maybe a try but I don't think that would work either.

> Help!! Thanks in advance!

> -Brent

Re:Not sure what I'm doing :)


FieldValues does not check for NULL.  You will need to check it yourself or
use FieldByName.

Quote
"Brent" <bsc...@usipp.net> wrote in message news:3c1c0d1e$1_1@dnews...
> I'm trying to set some variables using:

> MyVariable := qry.FieldValues['myfieldvalue'];

> However, if 'myfieldvalue' is NULL I get an exception...is there a way
> around this other than in the SQL statement itself. My goal is that even
if
> the value is NULL I can replace it with my own text (i.e. Not Available).
I
> tried an if statement but that too raised an exception. All I know to do
at
> this point is maybe a try but I don't think that would work either.

> Help!! Thanks in advance!

> -Brent

Other Threads