Results 1 to 5 of 5
  1. #1
    Join Date
    Dec 2003
    Location
    london
    Posts
    3

    Unanswered: problems with null fields when using msaccess with delphi

    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

  2. #2
    Join Date
    Feb 2002
    Posts
    2,232
    Normally, whether it is the sql statement or the application interface, you test for null - for example, like isnull...

  3. #3
    Join Date
    Dec 2003
    Location
    london
    Posts
    3
    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

  4. #4
    Join Date
    Feb 2002
    Posts
    2,232
    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.

  5. #5
    Join Date
    Aug 2004
    Posts
    10

    Read the Manual -- the Delphi manual

    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.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •