To insert data with SQLBulkOperations(ODBC API), data in MySQL database is error. n *sizeof(tagMessage) + 1 record is correct, other record is error.

example:

struct tagMessage
{
SQLCHAR szDate[9];
SQLINTEGER nDateInd;
char szTime[7];
SQLINTEGER nTimeInd;
char szFrom[11];
SQLINTEGER nFromInd;
char szTo[11];
SQLINTEGER nToInd;
char szContent[160];
SQLINTEGER nContentInd;
};

#define NUM_OF_ROW_EACH_FETCH 1
#define MAX_INSERT_ROW 1000

tagMessage aMsg[MAX_INSERT_ROW];

SQLHDBC hDbc;
SQLHENV hEnv;
SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &hEnv);
SQLSetEnvAttr(hEnv, SQL_ATTR_ODBC_VERSION, (void*)
SQL_OV_ODBC3, 0);
SQLAllocHandle(SQL_HANDLE_DBC, hEnv, &hDbc);

SQLRETURN ret;
char szConnStr[] = "DSN=Test;UID=root;PWD=;";
ret = SQLDriverConnect(hDbc, NULL,
(SQLCHAR*)szConnStr, SQL_NTS, NULL, 0, NULL,
(SQLUSMALLINT)SQL_DRIVER_NOPROMPT);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
{
printf("Connect success!\n");

SQLHSTMT hStmt;
SQLINTEGER nBindOffset = 0;
SQLUINTEGER NumRowsFetched;
SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt);

SQLSetStmtAttr(hStmt, SQL_ATTR_CURSOR_TYPE, (SQLPOINTER)SQL_CURSOR_DYNAMIC, 0);
SQLSetStmtAttr(hStmt, SQL_ATTR_ROW_BIND_TYPE, (SQLPOINTER)sizeof(tagMessage), 0);
SQLSetStmtAttr(hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)NUM_OF_ROW_EACH_FETCH, 0);

SQLSetStmtAttr(hStmt, SQL_ATTR_ROW_BIND_OFFSET_PTR, (SQLPOINTER)&nBindOffset, 0 );

SQLBindCol(hStmt, 1, SQL_C_CHAR, aMsg[0].szDate, sizeof(aMsg[0].szDate), &aMsg[0].nDateInd);
SQLBindCol(hStmt, 2, SQL_C_CHAR, aMsg[0].szTime, 7, &aMsg[0].nTimeInd);
SQLBindCol(hStmt, 3, SQL_C_CHAR, aMsg[0].szFrom, 11, &aMsg[0].nFromInd);
SQLBindCol(hStmt, 4, SQL_C_CHAR, aMsg[0].szTo, 11, &aMsg[0].nToInd);
SQLBindCol(hStmt, 5, SQL_C_CHAR, aMsg[0].szContent, 160, &aMsg[0].nContentInd);


char szSelect[] = "SELECT * FROM Test";
ret = SQLExecDirect(hStmt, (SQLCHAR*)szSelect, SQL_NTS);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
{
printf("ExecDirect success\n");
}

SQLFetch(hStmt);

nBindOffset = 1 * sizeof(tagMessage);
SQLSetStmtAttr(hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)MAX_INSERT_ROW, 0 );
ret = SQLBulkOperations(hStmt, SQL_ADD);
if (ret == SQL_SUCCESS || ret == SQL_SUCCESS_WITH_INFO)
{
printf("SQLBulkOperations success\n");
}
}