PDA

View Full Version : problems with null fields when using msaccess with delphi


ozwaa
12-30-03, 03:56
i have noticed a problem with null fields when using msaccess or mssqlserver2000 with delphi.I could not believe that this was happening with a product from a reputed company like microsft.
Could anyone advice on how to resolve this problem with delphi?
the error that pops with delphi is a conversion error and the program stops.
i'm surpirsed that nobody has noticed this major problem
thanks
ozwaa

rnealejr
01-02-04, 22:33
Normally, whether it is the sql statement or the application interface, you test for null - for example, like isnull...

ozwaa
01-11-04, 03:06
hi,
Thanks for your reply.. isnull does not work with delphi,its only good with with vb.Mysql and oracle takes care of the null problem when using delphi with them.I need to know about way to tacle this problem of nulls when using access and sqlserver 200 with delphi.
Thanks
edward
my email is edwardfonseca@yahoo.com

rnealejr
01-11-04, 16:04
There is an isnull function within sql server - download books online (the sql server reference for sql server), which you can use within your sql statement.

tgrigsby
08-20-04, 19:03
I realize this is months later, but for the benefit of anyone else scanning these forums...

Null fields in Access and SQL Server are normal. They represent a lack of data. Sophisticated development environments do *not* hide this fact. The reason you're having a problem is because you're not testing for the a null value. I would imagine you're doing something like

intval := Query1.FieldByName( 'field1' ).AsInteger;

or something similar. If it's possible that your field hasn't been populated yet, it could come back as a null value, in which case you may a conversion problem. What you're really seeing is the field value, which is a variant, attempting to convert a variant null to some other datatype. If you want to familiarize yourself with what's going on behind the scenes, look in the DB.PAS unit of your VCL.

In the meantime, if the value you're testing could contain a null, and that null could throw off your program, test for the null condition using the IsNull property of the TField class. In other words:

if ( not Query1.FieldByName( 'field1' ).IsNull ) then
....

Good luck.

:cool: