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

  • Event Date: April 15, 2014 The ability to effectively set sales goals, assign quotas and territories, bring new people on board and quickly make adjustments to the sales force is often crucial to success--and to the field experience! But for sales operations leaders, managing the administrative processes, systems, data and various departments to get it all right can often be difficult, inefficient and manually intensive. Register for this webinar and learn how you can: Align sales goals, quotas and …

  • Corporate e-Learning technology has a long and diverse pedigree. As far back as the 1980s, companies were adopting computer-based training to supplement traditional classroom activities. More recently, rich web-based applications have added streaming audio and video, real-time collaboration and other new tools to the e-Learning mix. At the same time, the growing availability of informal learning tools--a category that includes everything from web searches to social media posts--are having a major impact on …

Most Popular Programming Stories

More for Developers

Latest Developer Headlines

RSS Feeds