[+/-]
One common use for MySQL is the storage of binary data in
BLOB columns. MySQL supports four
different BLOB data types: TINYBLOB,
BLOB, MEDIUMBLOB, and
LONGBLOB, all described in
The BLOB and TEXT Types and Data Type Storage Requirements.
Data stored in a BLOB column can be accessed
using Connector/Net and manipulated using client-side code. There
are no special requirements for using Connector/Net with
BLOB data.
Simple code examples will be presented within this section, and a
full sample application can be found in the
Samples directory of the Connector/Net
installation.

User Comments
fs.Lenght is long.
Not compatible with UInt32.
fs.read(byte[], int, int)
requires int for buffer lenght.
The type of the variable FileSize is correct when assigning the return value of GetUInt32, but it makes conflicts in the GetBytes and in the Write methods, which only take integers. So you have to make that change in order to run the code.
I just wanted to clarify what Gabriela and Vladimir are talking about for anyone new to MySQL or C#/VB.
Remember that the examples in this section are not meant to be dropped directly into production code. For one thing, anyone thinking of storing a file in a database should make sure the file is small enough to fit in the blob type you choose. If you don't then MySQL will either throw an error (SQL STRICT mode only) or truncate your file data and issue a warning.
The MEDIUMBLOB field used in these examples can hold 16,777,216 bytes of data (16MB). The MEDIUMBLOB field gets dumped into an array of bytes when we read it from MySQL, so the biggest array we could possibly need would also hold 16,777,216 bytes. With that in mind, the casts from a long value (fs.Length) to a UInt32 (FileSize)and finally to an int (in myData.GetBytes()) will never cause a problem here, because the number returned by fs.Length will always be lower than the maximum value of an int.
There are a number of issues that arise when working with large chunks of BLOB data. See section 10.4.3 "The BLOB and TEXT Types" for more gotchas, and good luck!
Add your own comment.