How varbinary type in SQL Server use in function in C#
<p>I have encountered a type problem. I have in SQL Server table with this structure</p>

<pre><code>create table dbo.DataWithCompressedXML
(
    ID int not null,
    Data varbinary(max) not null,
)
</code></pre>

<p>The data looks like:</p>

<pre><code>0x0BC9C82C5600A2448592D4E21285E292A2CCBC74454500
</code></pre>

<p>Then I want take this value to C# to decompress, for decompress I use function near, after decompress I see the text like (This is a test string!!), but I can't understand in what type I must take my variable value from DB, and then use my function this is a test string!</p>

<pre><code>public static SqlBytes BinaryDecompress(SqlBytes input)
{
    if (input.IsNull)
        return SqlBytes.Null;

    int batchSize = 32768;
    byte[] buf = new byte[batchSize];

    using (MemoryStream result = new MemoryStream())
    {
        using (DeflateStream deflateStream = 
            new DeflateStream(input.Stream, CompressionMode.Decompress, true))
        {
            int bytesRead;
            while ((bytesRead = deflateStream.Read(buf, 0, batchSize)) &gt; 0)
                result.Write(buf, 0, bytesRead);
        }

        return new SqlBytes(result.ToArray());
    } 
}
</code></pre>