字段是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);

解决方案 »

  1.   

    在SQL SERVER可以用READTEXT
    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
      

  2.   

    如果你用的是SQLSERVER2000的话,直接用B/S的结构,可以返回XML
    另外,你端出TEXT和IMAGE数据类型的时候每一次不能超过8000个字节,SQLSERVER有这样的限制
      

  3.   

    利用readtext,具体方法见在线帮助,有例子.
      

  4.   

    我想达到的目的是在vc中 有没有什么odbc api 如SQLGetData
      

  5.   

    贴些帮助,不知道对你是否有帮助
    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
      

  6.   

    Examples
    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.
            }
        }