我最近用MFC里面的CRecordset类从SQLSERVER里面取数据,可是当从一部分字段里面取数据的时候出现异常提示说:“数据被截断!”,可是从ACCESS里面取数据就没有这种问题。
请问:
1、这是不是ODBC本身的问题?
2、如果我想仍然用ODBC有没有方法解决?
3、如何解决?
4、如果用ODBC解决不了,有什么其他更好的办法?
谢谢!
我知道高手都不太在乎送高分,不过我还是会送的!
再次感谢!

解决方案 »

  1.   

    你应该是用CRecordset绑定的吧!
    你看看在记录集的.cpp文件里默认的
    RFX_Date(pFX, _T("[field]"), m_field);改为RFX_Date(pFX, _T("[field]"), m_field,5000);//
      

  2.   

    我是直接用的CRecordset类,直接去CRecordset的实现文件里面去改吗?
      

  3.   

    为什么要用odbc呢?是不是有的功能ado不能实现呀。
      

  4.   

    PRB: Data Truncated Error With CRecordset Q210460
    --------------------------------------------------------------------------------
    The information in this article applies to:Microsoft Visual C++, 32-bit Editions, version 6.0--------------------------------------------------------------------------------
    SYMPTOMS
    When trying to move to record in a wizard-generated recordset, the following error can occur:Data truncated.
    You may also see the following TRACE message in the debug output window:
    Error: field data truncated during data fetch. CAUSE
    This error occurs when you are trying to access data in a text field that contains more than 255 characters. If you use the AppWizard or ClassWizard to generate your recordset class, the wizard creates a call to the function RFX_Text to transfer data between the database and your member variable. The fourth parameter of this function specifies the maximum allowed length of the data being transferred and the default value of this parameter is 255. RESOLUTION
    For each call to RFX_Text where the field can contain more than 255 characters, add a fourth parameter that is equal to the maximum length of that field. STATUS
    This behavior is by design. MORE INFORMATION
    Use the AppWizard to create a new MFC project with database support. Use an ODBC data source that contains one or more text fields with data longer than 255 characters.NOTE: When you build the project and run it, you may see the above error when you try to move to a record that contains long data in the text field. You can see it as soon as the recordset opens, if the first record meets this criteria. 
      

  5.   

    取字段的顺序和SQL语句的顺序不一致
      

  6.   

    恩,各位真是多谢,我是刚刚用VC不多久,前段时间遇到这个困难,然后公司人说:这是ODBC的问题,还是让我用SQLSERVER的BCP,我就想,其他东西能做出来,VC肯定可以啊,于是来问大家,哈哈,果真是能解决的!
    谢!
      

  7.   

    问题解决了,那个错误是因为表格是空的,所以当我MoveFirst();的时候出错了,加了一个判断就好了:if(mdb.IsEof()&&mdb.IsBof()) AfxMessageBox("The table is empty!") return FALSE;