Board index » delphi » Invalid Variant Type Conversion?

Invalid Variant Type Conversion?

What gives with this?  I cannot seem to get my TTable.Field[x].Value
into my TQuery.Params[x].Value because of these wacky variant
conversions.  Basically my problem is that if I just:

Given:  * TQuery.Params are the parameters to an SQL INSERT command,
             * Head2 is a dBase table
             * I'm simply trying to insert the values of the dBase
table into the Insert parameters:::

If I:
      Params[x].Value := DataMod.Head2.Fields[x].Value;

I get an "Unknown Data Type" whenever Fields[x].Value is EMPTY, that
is, a character field in the dBase table consists of all spaces.

I'm trying to write a function that:
     Params[x].Value := NotNull(DataMod.Head2.Fields[x].Value);

where:

function TImportForm.NotNull(p_Value: Variant): Variant;
begin
   if p_Value = varNull then
      Result := Variant(' ')
   else
      Result := p_Value;
end;

There are Logicals, a memo, date and numeric fields in this TTable.
Now I get an "Invalid Variant Type Conversion" on my character fields!
Anyone care to point me in the right direction?

Thanks!

 

Re:Invalid Variant Type Conversion?


Quote
Randy Abel wrote:

> What gives with this?  I cannot seem to get my TTable.Field[x].Value
> into my TQuery.Params[x].Value because of these wacky variant
> conversions.  Basically my problem is that if I just:

> Given:  * TQuery.Params are the parameters to an SQL INSERT command,
>              * Head2 is a dBase table
>              * I'm simply trying to insert the values of the dBase
> table into the Insert parameters:::

> If I:
>       Params[x].Value := DataMod.Head2.Fields[x].Value;

> I get an "Unknown Data Type" whenever Fields[x].Value is EMPTY, that
> is, a character field in the dBase table consists of all spaces.

> I'm trying to write a function that:
>      Params[x].Value := NotNull(DataMod.Head2.Fields[x].Value);

> where:

> function TImportForm.NotNull(p_Value: Variant): Variant;
> begin
>    if p_Value = varNull then
>       Result := Variant(' ')
>    else
>       Result := p_Value;
> end;

> There are Logicals, a memo, date and numeric fields in this TTable.
> Now I get an "Invalid Variant Type Conversion" on my character fields!
> Anyone care to point me in the right direction?

> Thanks!

Try using the .FieldByName('FieldName').AsString method instead.  It
will not blow up on blank records.

Re:Invalid Variant Type Conversion?


Thank you for the reply.  I've tried this now, and while I can load up
a record's worth of fields into my parameters, on the EXECSQL method,
I get an "Invalid Variant Type Conversion" error.  Any ideas?  Anyone?
Anyone?

On Thu, 09 Apr 1998 13:06:35 +0100, Dan Peluso <dpel...@dx-corp.com>
wrote:

Quote

>Try using the .FieldByName('FieldName').AsString method instead.  It
>will not blow up on blank records.

Other Threads