MySQL 5.0 Connector.NET Examples states:
GetBytes returns the number of available bytes in the field. In most cases this is the exact length of the field.
However, MySQL 5.0 Connector.NET Documentation lists the return value of GetBytes as the number of bytes read into the buffer.
To me this isn’t the same thing at all!
Regardless, my question is: what’s the most readable construction to get the content from the datasource into a MemoryStream object? I’m using the return value from GetBytes to increment the data index parameter of the GetBytes method but seemingly I keep overrunning the field because I get IndexOutOfRangeException being thrown.
I agree that the documentation for
MySqlDataReaderleaves a lot to be desired.When you pass
nullas thebufferargument,GetBytesreturns the total length of the field. When you pass a non-nullbufferargument,GetBytesreturns the number of bytes that were written into the buffer.