Can anyone see the error in the following code? It compiles and executes, but all the data is misaligned when inserted in the database. Someone please help, I've been working on this for weeks! =(


********************** code *********************************

void cDatabase::BulkInsertData(dataStruct DS[], SQLINTEGER numInserts)
{
if(numInserts)
{
SQLRETURN rc;
SQLUSMALLINT RowStatusArray[numInserts];
SQLINTEGER bindOffset = 0;

// set statement attributes
SQLSetStmtAttr(m_hStmt, SQL_ATTR_CURSOR_TYPE,
(void*)SQL_CURSOR_KEYSET_DRIVEN, 0);
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_BIND_TYPE, (void*)sizeof(dataStruct),
0);
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (void*)numInserts, 0);
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_STATUS_PTR, (void*)RowStatusArray,
0);
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_BIND_OFFSET_PTR, (void*)bindOffset,
0);

// execute a statement to retrieve rows from the table
rc=SQLExecDirect(m_hStmt, (SQLCHAR*) "SELECT * FROM data", SQL_NTS);
if(rc == SQL_ERROR)
printf("error\n");

// not working yet
SQLBindCol(m_hStmt, 1, SQL_C_SLONG, &DS[0].FrameID, 0, &DS[0].FrameIDLen);
SQLBindCol(m_hStmt, 2, SQL_C_CHAR, NULL, 0, 0);
SQLBindCol(m_hStmt, 3, SQL_C_UTINYINT, &DS[0].SubCode, 0,
&DS[0].SubCodeLen);
SQLBindCol(m_hStmt, 4, SQL_C_USHORT, &DS[0].Data, 0, &DS[0].DataLen);


rc = SQLBulkOperations(m_hStmt, SQL_ADD);
if(rc == SQL_ERROR)
{
printf("data insert error\n");
PrintError();
}
else if(rc == SQL_SUCCESS)
{
printf("data insert successful\n");
}
printf("after\n");
for(int j=0; j<numInserts;j++)
printf("%d, ", RowStatusArray[j]);
printf("\n");

// reset
SQLSetStmtAttr(m_hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)0, 0);
}
}

********************** code *********************************