How to use sqlbindparameter with a string that is not zero termianted
04:03 26 Dec 2025

When I bind a BSTR to a column in an Access database (.mdb) and insert data into this column, I keep getting 22001 which means the data has been truncated. The source of the data is shorter than the column width (12 characters). This is what I have got so far:

BOOL
odbc_iparam_bstr( SQLHSTMT stmt , int parameter_number , size_t column_size , const BSTR value )
{
    SQLRETURN   status              ;
    SQLLEN      length = SysStringByteLen( value )  ;
    SQLLEN      cch = SQL_DATA_AT_EXEC  ;

    status = SQLBindParameter( stmt ,
                   parameter_number , 
                   SQL_PARAM_INPUT ,
                   SQL_C_WCHAR , 
                   SQL_WCHAR ,
                   column_size ,
                   0 ,
                   value , 
                   &length  ,
                   &cch ) ;

    return( status == SQL_SUCCESS )  ;
}
odbc