Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 8 of 8 total
Thread Could not convert variant of type (Null) into type (String).
Mon, Apr 28 2008 12:11 AMPermanent Link

"Paul Coshott"
Hi All,

using DBISAM 4 with Delphi 7.

I am getting this error on a site.

exception class   : EVariantTypeCastError
exception message : Could not convert variant of type (Null) into type
(String).

I would like to write a utility that could search for any values in fields
that could cause this error. Any ideas?

Cheers,
Paul

Mon, Apr 28 2008 4:58 AMPermanent Link

Fernando Dias

Team Elevate Team Elevate

Paul,

Under what circunstances do you see this error message ?
Can you give us an idea about what code is executing when the error is
shown?

--
Fernando Dias
[Team Elevate]

Mon, Apr 28 2008 9:06 AMPermanent Link

Dan Rootham
Paul,

<< Could not convert variant of type (Null) into type (String). >>

The cause could be that your code assumes that there is always data,
but occasionally the field value is null. I have tripped up over this when
using ADO recordsets (example below).

You can protect against this error by using the "VarIsNull" function:

       if not VarIsNull(rsTest.Fields['cust_name'].Value) then
          sCustName := rsTest.Fields['cust_name'].Value;

--
Dan Rootham [Team Elevate]
Mon, Apr 28 2008 7:19 PMPermanent Link

"Adam H."
Hi Paul,

If you're doing a query, you could use the coalesce function to make sure
that a null value is never specified

ie:

select Coalesce(Myfield, '') as Myfield, Coalesce(MyAmount, 0) as Amount
From Mytable


> You can protect against this error by using the "VarIsNull" function:
>
>        if not VarIsNull(rsTest.Fields['cust_name'].Value) then
>           sCustName := rsTest.Fields['cust_name'].Value;

Hi Dan,

Just wondering if this is any different to
rsTest.Fields['cust_name'].isnull?

Cheers

Adam.
Tue, Apr 29 2008 8:18 AMPermanent Link

Dan Rootham
Adam,

<< Just wondering if this is any different to
rsTest.Fields['cust_name'].isnull? >>

The IsNull construct isn't available for ADODB_TLB._Recordset,
so you have to use VarIsNull instead. VarIsNull handles variants,
while IsNull operates on the TField property of TDataset and
its descendants.

Sorry if I confused: it's just that I'm more accustomed to the use
of VarIsNull.

And yes, VarIsNull and IsNull are similar in that both are testing
for a null value.

Regards
Dan Rootham [Team Elevate]
Tue, Apr 29 2008 8:48 AMPermanent Link

Joze
On Tue, 29 Apr 2008 08:18:15 -0400, Dan Rootham <roothamd@yahoo.co.uk> wrote:

>And yes, VarIsNull and IsNull are similar in that both are testing
>for a null value.

Is this true also for date fields?

How are you testing for null dates?
I am doing it with DateToStr(MyDate)<>'30.12.1899'

Is there another way to test it?

Regards,

Joze
Tue, Apr 29 2008 12:09 PMPermanent Link

"Jose Eduardo Helminsky"
Joze

<<
How are you testing for null dates?
I am doing it with DateToStr(MyDate)<>'30.12.1899'
>>

Yes, there is another (and easy) way to do this

if MyDate = 0 then begin
  ...
end;

Eduardo

Tue, Apr 29 2008 8:02 PMPermanent Link

"Paul Coshott"
> How are you testing for null dates?
> I am doing it with DateToStr(MyDate)<>'30.12.1899'
>>>
>
> Yes, there is another (and easy) way to do this
>
> if MyDate = 0 then begin
>   ...
> end;
>
> Eduardo

Hi Guys,

thanks for all the answers. I am just waiting on a copy of the clients data
so I can test it.

Cheers,
Paul

Image