Need help saving and retrieving RichTextBox.rtf to/from image field in SQL Server

S

Sam

Hello.

I need to save the rtf property to an image field in SQL Server. I'm
currently saving it, but I can't figure out how to then retrieve it
and display it into the rtf. I have to have Option Strict On. I've
tried all sorts of stuff, and can't seem to get it.

Here's how I save to image field.

****************************
Dim ByteArray() As Byte
ByteArray = System.Text.Encoding.UTF8.GetBytes(rtfBox.Rtf)

.Rows(0).Item(RTF_FIELD) = ByteArray

'Then save to database using Adapter.
****************************

Is this right? If so, how do I then go about doing the reverse?

Thanks...
 
S

Sam

I'm able to get it to save and retrieve - sort of.... As soon as I put
an image in the RichTextBox, it doesn't save (maybe it saves, but it
doesn't retrieve?) anything from the image on. Here's what I'm doing.
I've got a SQL Server database and saving the rtf to an image field.

------------SAVE----------------------------------------------
Dim ByteArray() As Byte
Dim ioMemoryStream As New System.IO.MemoryStream

rtfBox.SaveFile(ioMemoryStream, RichTextBoxStreamType.RichText)
ByteArray = ioMemoryStream.ToArray

..Rows(0).Item(g_dsMasterCobraLetters.RTF_FIELD) = ByteArray

'Then save using a data adapter.
---------------------------------------------------------------

------------RETRIEVE-------------------------------------------
Dim ioMemoryStream As New System.IO.MemoryStream
Dim ByteArray() As Byte

ByteArray = CType(.Rows(0).Item(.RTF_FIELD), Byte())
ioMemoryStream = New System.IO.MemoryStream(ByteArray)
rtfBox.LoadFile(ioMemoryStream, RichTextBoxStreamType.RichText)
 

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