字段是text类型的 如何取出来呢? 用SQLBindCol试过,好像不行,绑定的变量用的cstring, 又试过sqlgetdata但是不知道是用得不对还是怎么的,取出来的数据是乱码
代码如下:nRet = SQLFetch(hstmt);
if (nRet == SQL_NO_DATA)
break;CString szStr;
nRet = SQLGetData
(hstmt,5,SQL_C_CHAR,&szStr,sizeof(szStr),&nStrLen);
代码如下:nRet = SQLFetch(hstmt);
if (nRet == SQL_NO_DATA)
break;CString szStr;
nRet = SQLGetData
(hstmt,5,SQL_C_CHAR,&szStr,sizeof(szStr),&nStrLen);
FOR EXAMPLE:USE pubs
GO
DECLARE @ptrval varbinary(16)
SELECT @ptrval = TEXTPTR(pr_info)
FROM pub_info pr INNER JOIN publishers p
ON pr.pub_id = p.pub_id
AND p.pub_name = 'New Moon Books'
READTEXT pub_info.pr_info @ptrval 1 25
GO
另外,你端出TEXT和IMAGE数据类型的时候每一次不能超过8000个字节,SQLSERVER有这样的限制
Bulk Copying text and image Data
Large text, ntext, and image values are bulk copied using the bcp_moretext function. You code bcp_bind for the text, ntext, or image column with a pData pointer set to NULL indicating the data will be provided with bcp_moretext. It is important to specify the exact length of data supplied for each text, ntext, or image column in each bulk-copied row. If the length of the data for a column is different from the column length specified in bcp_bind, use bcp_collen to set the length to the proper value. A bcp_sendrow sends all the non-text, non-ntext, and non-image data; you then call bcp_moretext to send the text, ntext, or image data in separate units. Bulk copy functions determine that all data has been sent for the current text, ntext, or image column when the sum of the lengths of data sent through bcp_moretext equals the length specified in the latest bcp_collen or bcp_bind.bcp_moretext has no parameter to identify a column. When there are multiple text, ntext, or image columns in a row, bcp_moretext operates on the text, ntext, or image columns starting with the column having the lowest ordinal number and proceeding to the column with the highest ordinal number. bcp_moretext goes from one column to the next when the sum of the lengths of data sent equals the length specified in the latest bcp_collen or bcp_bind for the current column.
See Alsobcp_bindbcp_collenbcp_moretextbcp_sendrow
SQLHDBC hDbc = NULL;
SQLHSTMT hStmt = NULL;
long lEmpID;
PBYTE pPicture;
SQLINTEGER pIndicators[2];// Get an environment, connection, and so on.
...// Get a statement handle and execute a command.
SQLAllocHandle(SQL_HANDLE_STMT, hDbc, &hStmt);if (SQLExecDirect(hStmt,
(SQLCHAR*) "SELECT EmployeeID, Photo FROM Employees",
SQL_NTS) == SQL_ERROR)
{
// Handle error and return.
}// Retrieve data from row set.
SQLBindCol(hStmt, 1, SQL_C_LONG, (SQLPOINTER) &lEmpID, sizeof(long),
&pIndicators[0]);while (SQLFetch(hStmt) == SQL_SUCCESS)
{
printf("EmployeeID: %d\n", lEmpID); // Call SQLGetData to determine the amount of data that's waiting.
if (SQLGetData(hStmt, 2, SQL_C_BINARY, pPicture, 0, &pIndicators[1])
== SQL_SUCCESS_WITH_INFO)
{
printf("Photo size: %ld\n\n", pIndicators[1]); // Get all the data at once.
pPicture = new BYTE[pIndicators[1]];
if (SQLGetData(hStmt, 2, SQL_C_DEFAULT, pPicture,
pIndicators[1], &pIndicators[1]) != SQL_SUCCESS)
{
// Handle error and continue.
} delete [] pPicture;
}
else
{
// Handle error on attempt to get data length.
}
}