How to bind SQL Server large string length data type with CRecordset derived class ?


Hi,
Can any expert help me?

I'm using the MFC ODBC consumer wizard to create my CRecorset derived class to bind fields of my SQL Server table.

But at run-time at rs->Open(...) line, it launches a Debug Assertion Failed message.

I already realized that it is about of having a char(500) field in my table. That is the cause!
And I read somewhere that MFC allows binding to less than 256 characters length by default.

Is there any way or any function that I can call before the Open function to set as maximum length to 500 for the binding ?


Here's some code:

in SQL Server I have my TABLE:
----------------------------------
id int
my_string char(500)


in Visual Studio I have this class generated by the wizard:
---------------------------------------------------------------
class CMyClassRS : public CRecordset
{
public:
CMyClassRS(CDatabase* pDatabase = NULL);
DECLARE_DYNAMIC(CMyClassRS)

int m_id;
CStringA m_my_string;
........


and in my main:
-----------------
....
CMyClassRS *rs = new CMyClassRS();

rs->Open(CRecordset::snapshot,"select * from TABLE");

//Here it launches the message at run-time



I'll really appreciate any help.

Last edited on

Any help please ?!
Maybe this helps: https://msdn.microsoft.com/en-us/library/eshhha8h.aspx
Character data beyond 255 characters is truncated by default when mapped to CString. You can extend the truncation length by explicitly setting the nMaxLength argument of RFX_Text.



Wow!! so simple solution!

void CMyClassRS ::DoFieldExchange(CFieldExchange* pFX)
{
RFX_Text(pFX, _T("[my_string]"), m_my_string, 500);
...


Really thanks Thomas, helped a lot.
Topic archived. No new replies allowed.