CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 5 of 5
  1. #1
    Join Date
    Mar 2004
    Posts
    28

    Empty string stored as NULL by MFC for MS SQL 2K

    Trying to following other SQL recommendations, many of my table columns do not allow NULLs.
    However, when I have code like this:

    recordSet.Edit();
    recordSet.m_MyColumn = '';
    recordSet.Update();

    With "MyColumn" not allowing NULLs, I get the exception "Cannot insert NULL values into column..."

    This is because of this code in MFC during DoFieldExchange RFX_Text (DBRFX.cpp)

    case CFieldExchange::MarkForUpdate:
    if (value.IsEmpty())
    pFX->m_prs->SetNullFieldStatus(nField - 1);
    else
    pFX->m_prs->ClearNullFieldStatus(nField - 1);

    value.IsEmpty is TRUE, so the field (column) is marked as NULL.

    Any suggestions how to get the empty string into MyColumn?


    Thanks for reading this far.

    Jim O'Leary

  2. #2
    Join Date
    Mar 2005
    Posts
    2

    Question Re: Empty string stored as NULL by MFC for MS SQL 2K

    Jim,
    Did you ever get a fix for this? I have the same issue and am now inserting a space into the fields. I don't like it but it works. I would like to find a better solution if you do have one could you share it.

    Thanks,
    Darstan

  3. #3
    Join Date
    Mar 2004
    Posts
    28

    Re: Empty string stored as NULL by MFC for MS SQL 2K

    Darstan-

    Unfortunately, I do not have a fix or a better workaround to recommend.

    Ulitmately, I decided to take my chances and allow NULLs.

    I wish I had better news.

    jim

  4. #4
    Join Date
    Nov 2004
    Location
    Poland
    Posts
    1,355

    Re: Empty string stored as NULL by MFC for MS SQL 2K

    What RDBMS is that?

    If SQL Server 2000+ or Oracle 9i+ than (for sure) U can use "instead of" triggers to do that.

    U can also try to override class (and IsEmpty() function) that stands behind "value" so in case of empty string "value.IsEmpty()" will return FALSE.

    But IMHO it is better to insert nulls (in case of empty strings).


    Best regards,
    Krzemo.

  5. #5
    Join Date
    Mar 2004
    Posts
    28

    Re: Empty string stored as NULL by MFC for MS SQL 2K

    Krzemo-

    Thank you for your response. It neven occurred to me to consider an "instead of" trigger.

    Nor would I have thought to try an override for IsEmpty.

    I appreciate your consideration of my problem

    jim

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured