When fetching long string values or binary data, there are methods that you can use to fetch the data in pieces. For binary data, use the GetBytes method, and for string data, use the GetChars method. Otherwise, BLOB data is treated in the same manner as any other data you fetch from the database.
For more information, see GetBytes method and GetChars method.
To issue a statement that returns a string using the GetChars method
Declare and initialize a Connection object.
Open the connection.
Add a Command object to define and execute a SQL statement.
SACommand cmd = new SACommand( "SELECT int_col, blob_col FROM test", conn ); |
Call the ExecuteReader method to return the DataReader object.
SADataReader reader = cmd.ExecuteReader(); |
The following code reads the two columns from the result set. The first column is an integer (GetInt32( 0 )
), while the second column is a LONG VARCHAR. GetChars is used to read 100 characters at a time from the LONG VARCHAR column.
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; } |
Close the DataReader and Connection objects.
reader.Close(); conn.Close(); |
Send feedback about this page via email or DocCommentXchange | Copyright © 2008, iAnywhere Solutions, Inc. - SQL Anywhere 11.0.0 |