Scripting out varbinary data

J

Jonathan Sion

Hi,
I need to script out data in a table (that is, generate an INSERT
statement for each row, to be executed on another database), and it
has a vrabinary(max) column. i need to generate a text file with this
binary (which is not a unicode string or anything like that... this is
NOT 'conversion to a string' problem. its abinary that would stay a
binary)

(So I get data - SQLDataAdapter.Fill into my DataTable - then
itereate it. the values i need appear as Byte array... )

any idea \code snippet that does this?

thank you very much!
Jonathan
 
J

Jeff Johnson

I need to script out data in a table (that is, generate an INSERT
statement for each row, to be executed on another database), and it
has a vrabinary(max) column. i need to generate a text file with this
binary (which is not a unicode string or anything like that... this is
NOT 'conversion to a string' problem. its abinary that would stay a
binary)

Actually, it IS a "conversion to string" problem, because you need to
represent your binary value as a string. It's not hard:

// Warning: air code!
byte[] myVarbinaryData;
// Do something to fill the array with data

StringBuilder binBuilder = new StringBuilder("0x");

foreach(byte b in myVarbinaryData)
{
binBuilder.Append(b.ToString("X:2"));
}

// Now use binBuilder.ToString() to get a value like
// 0x6530220D0A426C616820626C616820626C6168
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top