Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Db table Null fields? 2

Status
Not open for further replies.

corsair2

IS-IT--Management
Feb 21, 2001
55
GB
Hi Folks

have got the following line as part of a quick and dirty program to try and clean up a Db table from an old mainframe app. -

if not(form1.ADOTable1.FieldValues['Field3'].IsNull) then..

Unfortunately, whenever it actually comes across a null field it throws up a "variant conversion error".
Anyone point me in the right direction on how to pick up null fields in Db tables (so they can be skipped)?
I suppose I could trap this specific error and try and get round it that way but seems a bit inelegant...

Regards
 
use the FieldByName method instead of FieldValues.
FieldByName returns a TField whereas FieldValues returns a variant.

you have different methods to cope with null fields :

Code:
a) if form1.ADOTable1.FieldValues['Field3'] <> null then..
b) if not form1.ADOTable1.FieldByName['Field3'].IsNull then..
c) access your field through its native format
var s : string;
...
s:=form1.ADOTable1.FieldByName['Field3'].AsString;
if the field was null, s will be ''

hope this helps,

--------------------------------------
What You See Is What You Get
 
hi

If you want to replace the NULLs would it not be easier to do it as SQL? eg

Update myTable
set myField = ''
where myField is Null

lou

 
Note that MS-SQL will return .IsNull = False for VarChar fields even when the column has never has anything assigned to it; you have to check .AsString <> ''.

(Also note that FieldByName is a function and uses parentheses not square brackets)

Cheers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top