Read / Write BLOBs from / to SQL Server using C#

Obtaining BLOB Values from a Database Binary large objects (BLOBs) contain gigabytes of data. When accessing the data in the BLOB field, use the GetBytes or GetChars typed accessors of the DataReader, which fill an array with data.

GetBytes and GetChars will return a long value, which represents the number of bytes or characters returned. If you pass a null array to GetByte or GetChars, the long value returned will be the total number of bytes or characters in the BLOB.

Writing BLOB Values to a Database You can write a binary large object (BLOB) to a database as either binary or character data, depending on the type of field at your data source. To write a BLOB value to your database, issue the appropriate INSERT or UPDATE statement and pass the BLOB value as an input parameter.

If the BLOB is stored in binary format, such as a SQL Server image field, you can pass an array of type byte as a binary parameter.

Diagram