How to get the size of blob data

I currently get blob data from a SQL database but a collegue pointed out that I wasn’t making it easy for him to see how much data is returned from the query. After a bit of head-scratching he found the solution which as usual is not in the MSDN documentation.

Here’s an example of how to do it…
using (SqlDataReader reader = cmd.ExecuteReader(CommandBehavior.SequentialAccess))
reader.Read(); // Get length of data by pass null as the byte array parameter
long dataLength = reader.GetBytes(0, 0, null, 0, 0);
Simple really….if only Microsoft would tell us this in the first place…!

Tagged . Bookmark the permalink.

Leave a Reply