I am attempting to pass a table-valued parameter as a parameter in a stored procedure using ODBC. I have followed examples from MSDN, but receive the following error when I call SQLBindParameter:
HY004 [Microsoft][ODBC SQL Server Driver]Invalid SQL data type
Here is my code.
//Allocate stament handle
SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt);
//Prep command
SQLPrepare(hStmt, (SQLCHAR*)"{call myStoredProc(?)}", SQL_NTS)
//Variables
const int arraySize = 2;
const int varcharSize = 30;
SQLCHAR *myUserDefTableName = (SQLCHAR *) "myUserDefTableName";
SQLLEN myUserDefTableInd = 0;
//bind table item
int result = SQLBindParameter(hStmt,
1,// ParameterNumber
SQL_PARAM_INPUT,// InputOutputType
SQL_C_DEFAULT,// ValueType
SQL_SS_TABLE,// Parametertype
(SQLINTEGER)arraySize,// ColumnSize - for a TVP this the row array size
0,// DecimalDigits - for a TVP this is the number of columns in the TVP
(SQLPOINTER)myUserDefTableName,// ParameterValuePtr - for a TVP this is the type name of the TVP
SQL_NTS,// BufferLength - for a TVP this is the length of the type name or SQL_NTS
&myUserDefTableInd);// StrLen_or_IndPtr - for a TVP this is the number of rows available
//bind columns for the table-valued parameter
//and execute command
...
I've also found this on MSDN:
A table-valued parameter column cannot be bound as type SQL_SS_TABLE. If SQLBindParameter is called with ParameterType set to SQL_SS_TABLE, SQL_ERROR is returned and a diagnostic record is generated with SQLSTATE=HY004, "Invalid SQL data type". This can also occur with SQLSetDescField and SQLSetDescRec.
But I am trying to bind the table item, not the table columns. This almost seems to directly contradict what is stated in their code examples. I am unsure as to why this error occurs. Any ideas?
Many thanks.