Solving the ODBC "Data truncated" error

When you derive a class from CRecordset, the default maximum length assigned by the AppWizard for a string or array during a transfer is 255. A "Data Truncated" error is displayed whenever you attempt to transfer records with fields bigger than that.

To solve the problem, specify the length required as the fourth parameter of the RFX_Text() function in the AFX_FIELD_MAP section of your CRecordset derived class method file. The maximum length you can set it to is INT_MAX (2147483647) which is the maximum length of a CString object.

The source below shows the COST_INFO and BENEFITS columns of the table accessed being assigned a maximum length of 1000 characters each.


//{{AFX_FIELD_MAP(CProjectsSet)
RFX_Text(pFX, _T("[COST_INFO]"), m_COST_INFO, 1000);
RFX_Text(pFX, _T("[BENEFITS]"), m_BENEFITS, 1000);
//}}AFX_FIELD_MAP




Comments

  • Is this true for SQL server 6.5

    Posted by Legacy on 03/10/1999 12:00am

    Originally posted by: Tommy Quitt

    As much as I know, Ms SQL server 6.5 does not support longer strings that 255 chars.
    Is this true or does this RFX_TEXT change will allow longer strings on SQL server 6.5 too?

    Tommy

    Reply
  • Problems with changing RFX_Text...

    Posted by Legacy on 01/07/1999 12:00am

    Originally posted by: Alexander Keck

    Hi there!
    
    

    The same problem occures if you use Binary fields.
    RFX_Binary() also supports the third parameter for the maximum length, witch is also 255 as default.
    This works verry well here, BUT the ClassWizzard is unable to handle this.... It allways shows up a Messagebox telling you:
    Parsing Error: Expected ")".
    Input Line: "RFX_Binary(pFC, _T([Fieldname]"), m_Variable, 1000);"

    Possible Solution (not testet until now):
    Place the RFX_Text (or RFX_Binary) outside the ClassWizzard Insert comments:
    //{{AFX_FIELD_MAP(CCLClientBinaryRecordset)
    RFX_Text(pFX, _T("[TextField]"), m_Text);
    //}}AFX_FIELD_MAP
    RFX_Binary(pFX, _T("[BinaryField]"), m_Binary, 0x40000);

    greetings
    Alex

    Reply
Leave a Comment
  • Your email address will not be published. All fields are required.

Top White Papers and Webcasts

  • QA teams don't have time to test everything yet they can't afford to ship buggy code. Learn how Coverity can help organizations shrink their testing cycles and reduce regression risk by focusing their manual and automated testing based on the impact of change.

  • On-demand Event Event Date: September 10, 2014 Modern mobile applications connect systems-of-engagement (mobile apps) with systems-of-record (traditional IT) to deliver new and innovative business value. But the lifecycle for development of mobile apps is also new and different. Emerging trends in mobile development call for faster delivery of incremental features, coupled with feedback from the users of the app "in the wild." This loop of continuous delivery and continuous feedback is how the best mobile …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds