读取长字符串值或二进制数据时,可以使用一些方法分段读取数据。对于二进制数据,可使用 GetBytes 方法;而对于字符串数据,则可使用 GetChars 方法。否则,BLOB 数据的处理方法与从数据库读取的任何其它数据的处理方法相同。
有关详细信息,请参见GetBytes 方法和GetChars 方法。
声明并初始化一个 Connection 对象。
打开该连接。
添加一个 Command 对象以定义并执行一条 SQL 语句。
SACommand cmd = new SACommand( "SELECT int_col, blob_col FROM test", conn ); |
调用 ExecuteReader 方法以返回 DataReader 对象。
SADataReader reader = cmd.ExecuteReader(); |
下面的代码读取结果集中的两列。第一列是一个整数 (GetInt32( 0 )
),而第二列的类型为 LONG VARCHAR。GetChars 用于从 LONG VARCHAR 列一次读取 100 个字符。
int length = 100; char[] buf = new char[ length ]; int intValue; long dataIndex = 0; long charsRead = 0; long blobLength = 0; while( reader.Read() ) { intValue = reader.GetInt32( 0 ); while ( ( charsRead = reader.GetChars( 1, dataIndex, buf, 0, length ) ) == ( long ) length ) { dataIndex += length; } blobLength = dataIndex + charsRead; } |
关闭 DataReader 和 Connection 对象。
reader.Close(); conn.Close(); |
![]() |
使用DocCommentXchange 讨论此页。
|
版权 © 2010, iAnywhere Solutions, Inc. - SQL Anywhere 12.0.0 |