Save text stream as binary in database

J

Jon

I have a sql table that hold binary files as blobs. Our customers store
attachments for their work orders in them, anything from xml files to zip
files. Normally, these files first exist on the hard drive and are converted
to a byte array and saved to the database in an image type field.

Four the web version of this, our customers will be entering text into a
form and when the form is submitted, the text will be saved to a simple
string variable.

I need to them convert that string var into a byte array to allow it to be
saved to the database, just as if it were a text file.

I know how to do this using an actual file, but my brain is not letting me
make the leap to using a string var, instead of the file.

What's the best way to do this? Oh, and I can't just save it as a varchar in
the db because later on, in the client application, it will be looking to
take the data and create an actual text file on an end user's hard drive.

Thanks
 
L

Larry Lard

Jon wrote:
[snip]
I need to them convert that string var into a byte array

Encoding.GetBytes:
Encodes all or part of a specified String or character array into a
byte array.

Now, choosing *which* Encoding to use is the interesting bit.
ASCIIEncoding might be appropriate, if the text is pure 7 bit. Or maybe
Encoding.Default if your codepage is constant. Or Encoding.Unicode to
be absolutely sure.
 
C

Cor Ligthert [MVP]

Jon,

In my idea is the best way to do this to encapsulate both in a
dataset/datatable.

Have a look at this sample on our website
(the text field is not yet added, however that is of course a piece of cake)

http://www.windowsformsdatagridhelp.com/default.aspx?ID=0c1491cc-bed8-4525-b2b2-dd138c31a825I hope this helps,Cor"Jon" <[email protected]> schreef in berichthave a sql table that hold binary files as blobs. Our customers storeattachments for their work orders in them, anything from xml files to zipfiles. Normally, these files first exist on the hard drive and are convertedto a byte array and saved to the database in an image type field.>> Four the web version of this, our customers will be entering text into aform and when the form is submitted, the text will be saved to a simplestring variable.>> I need to them convert that string var into a byte array to allow it to besaved to the database, just as if it were a text file.>> I know how to do this using an actual file, but my brain is not letting memake the leap to using a string var, instead of the file.>> What's the best way to do this? Oh, and I can't just save it as a varcharin the db because later on, in the client application, it will be looking totake the data and create an actual text file on an end user's hard drive.>> Thanks>
 

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