在线等待 进门就送 如 何 从 库 中 取 不 限 长 类 型 的 字 段 的 数 据 如TEXT (sunyt )

在线等待 如 何 从 库 中 取 不 限 长 类 型 的 字 段 的 数 据 如TEXT ?
[46 byte] By [sunyt-sunyt] at [2008-2-13]
# 1
字段是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);
sunyt-sunyt at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 2
ADODB.Stream试试
BluePig-ampmiao at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 3
如果不用ado只用api呢?
sunyt-sunyt at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 4
在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

leimin-黄山光明顶 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 5
请问在程序中如何实现呢?
sunyt-sunyt at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 6
stream
or
convert
erp2-天涯劍 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 7
readtext
rex_wang-王 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 8
用法见在线帮助.
rex_wang-王 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 9
如果你用的是SQLSERVER2000的话,直接用B/S的结构,可以返回XML
另外,你端出TEXT和IMAGE数据类型的时候每一次不能超过8000个字节,SQLSERVER有这样的限制
librastar2001-天平 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 10
利用readtext,具体方法见在线帮助,有例子.
z5wjz-z5wjz at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 11
我想达到的目的是在vc中 有没有什么odbc api 如SQLGetData
sunyt-sunyt at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 12
anybody?
sunyt-sunyt at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 13
贴些帮助,不知道对你是否有帮助
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 Also

bcp_bind

bcp_collen

bcp_moretext

bcp_sendrow

sky_blue-蓝天2007 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...
# 14
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.
}
}

sky_blue-蓝天2007 at 2007-10-20 > top of Msdn China Tech,MS-SQL Server,基础类...