我試圖在存儲過程中使用ODBC傳遞一個表值參數作爲參數。我按照從MSDN的例子,但是當我打電話收到以下錯誤的SQLBindParameter:在使用ODBC時,綁定表值參數的錯誤C++
HY004 [微軟] [ODBC SQL Server驅動程序]無效的SQL數據類型
這裏是我的代碼。
//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
...
我也發現這個MSDN上:
表值參數列不能綁定類型SQL_SS_TABLE。如果使用ParameterType設置爲SQL_SS_TABLE來調用SQLBindParameter,則會返回SQL_ERROR,並使用SQLSTATE = HY004,「無效的SQL數據類型」生成診斷記錄。這也可能發生在SQLSetDescField和SQLSetDescRec中。
但我想綁定表項,而不是表列。這似乎與代碼示例中所述的內容直接矛盾。我不確定爲什麼發生此錯誤。有任何想法嗎?
非常感謝。