sforbes
asked on
ODBC, SqlServer and VarBinary Columns
How does one use the binary fields in MSSQL from Visual C++?
When using the class wizard to create the class for the DB Table,
the binary field maps to a CByteArray. I can write to this table,
but if I read, I get a data truncation error. The rather ambiguous
help files on MFC suggest using CLongBinary instead, but the
CLongBinary documentation says to use CByteArray.
When using the class wizard to create the class for the DB Table,
the binary field maps to a CByteArray. I can write to this table,
but if I read, I get a data truncation error. The rather ambiguous
help files on MFC suggest using CLongBinary instead, but the
CLongBinary documentation says to use CByteArray.
Continuing with what i said earlier
the following function
it should be DFX not DDX
The DFX_Binary function transfers arrays of bytes between the field data members of a CDaoRecordset object and the columns of a record on the data source. Data is mapped between type DAO_BYTES in DAO and type CByteArray in the recordset.
void AFXAPI DFX_Binary( CDaoFieldExchange* pFX, LPCTSTR szName, CByteArray& value, int nPreAllocSize = AFX_DAO_BINARY_DEFAULT_SIZ E, DWORD dwBindOptions = 0 );
u can go to afxdao.h file and change the size of AFX_DAO_BINARY_DEFAULT_SIZ E
then U will get better results.
Hope this helps
Regards
the following function
it should be DFX not DDX
The DFX_Binary function transfers arrays of bytes between the field data members of a CDaoRecordset object and the columns of a record on the data source. Data is mapped between type DAO_BYTES in DAO and type CByteArray in the recordset.
void AFXAPI DFX_Binary( CDaoFieldExchange* pFX, LPCTSTR szName, CByteArray& value, int nPreAllocSize = AFX_DAO_BINARY_DEFAULT_SIZ
u can go to afxdao.h file and change the size of AFX_DAO_BINARY_DEFAULT_SIZ
then U will get better results.
Hope this helps
Regards
ASKER
We are using ODBC not DAO. The problem we are experiencing is that we do the following:
// Sometable is empty
Sometable tt;
tt.Open(ourDB_p);
tt.AddNew(...)
tt.Update()
tt.Close()
Everthing is fine to here. When at another time we do:
Sometable tt;
tt.Open(ourDB_p);
The open throws an exception, the text of which tells us that the Data has been truncated.
Our thesis is that the Rfx_Binary function is not handling the CByteArray properly.
Why not?
// Sometable is empty
Sometable tt;
tt.Open(ourDB_p);
tt.AddNew(...)
tt.Update()
tt.Close()
Everthing is fine to here. When at another time we do:
Sometable tt;
tt.Open(ourDB_p);
The open throws an exception, the text of which tells us that the Data has been truncated.
Our thesis is that the Rfx_Binary function is not handling the CByteArray properly.
Why not?
Oops
sorry any how the RFX_Binary is implemented in ODBC also check R U passing the fourth parameter nMaxLength and not using the default one which is 255?
sorry any how the RFX_Binary is implemented in ODBC also check R U passing the fourth parameter nMaxLength and not using the default one which is 255?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks very much. We didn't think of changing the generated code, but sometimes you have to apparently!
Its better use CByteArray because U get more functionalities
If Ur Requirement gets satisfy with CLongBinary go ahead with it there is absolutely no probs with it
only concern is UR getting a warning (hoping no error)of truncation that any way will come even if U use CLongBinary because the DDX_Binary imlementation problems
Regards