Link to home
Start Free TrialLog in
Avatar of xstar
xstar

asked on

Binary field in SQL Server

Hi,

I'm using CRecordset to open a SQL server table through ODBC. I have encountered a problem with  a binary field. The binary data retrieved will always be different from what I have added to the table. I have added the CRecordset using the "insert new class" and the variable type of the field is CByteArray.  Is there anything wrong with this?  The codes generate in the DoFieldExchange function is :

RFX_Binary(pFX, _T("[Data]"), m_Data);

Thanks.
Avatar of Axter
Axter
Flag of United States of America image

>>RFX_Binary(pFX, _T("[Data]"), m_Data);

You don't have a max size.

Example:
RFX_Binary(pFX, _T("[Image]"), m_Image, 8000000);
Please also show your *.h file declaration of m_Data within your CRecordset derived class.

And can you show how you're using it.
Avatar of xstar
xstar

ASKER

CByteArray      m_Data;

I have added in the max size but I still cannot get back the correct data.
Avatar of xstar

ASKER

Hi,

I finally get back the correct data.

Previous when adding of new record to database, I have tried to :
m_Data.RemoveAll(); //clear all objects
m_Data.Add(1); //add until the max length(10)
.....

This does not work so I try with :
m_Data.SetSize(10);
m_Data[0] = 1;
..........

This works fine.  Isn't adding and setting size the same as long as the final array size is 10?

>>Isn't adding and setting size the same as long as the final array size is 10?

It should be the same.  I'm not sure why it would fail using first method.
ASKER CERTIFIED SOLUTION
Avatar of GranMod
GranMod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial