CRecordset and nulls

This is a discussion on CRecordset and nulls within the Windows Programming forums, part of the Platform Specific Boards category; Hi all I have a CRecordset derived class, with some string fields which correspond to non-nullable columns in the database. ...

  1. #1
    Fish
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    6

    CRecordset and nulls

    Hi all

    I have a CRecordset derived class, with some string fields which correspond to non-nullable columns in the database. Unfortunately, it seems that ODBC converts empty strings to null, so my updates fail if I have empty strings. I can't change the database or data. Any suggestions?

    Thanks in advance

    R

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,855
    >> I can't change the database or data.

    that makes it hard...

    >>Any suggestions?

    If string is empty
    set string = "NULL"
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  3. #3
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    it seems that ODBC converts empty strings to null, so my updates fail if I have empty strings.
    Thats correct. Not even ODBC, but probably the database. Some databases don't allow empty strings. An empty string indeed is null. You will need to fill the strings or build your own SQL statement for updates.
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  4. #4
    Fish
    Join Date
    Jul 2005
    Location
    San Diego
    Posts
    6
    Setting the strings = "NULL" would be changing the data.

    Empty strings are not null. It's not the database, it is ODBC, which does if (field.IsEmpty()) field.m_null = true. The problem seems to be that MFC doesn't recognize a difference between empty and null.

Popular pages Recent additions subscribe to a feed

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21