问题
I got an Oracle table with a number of columns. 1 of these columns in a BLOB datatype. I got a simple query in VB.NET that is retrieving all data from this table, and populates my form. However, I'm having some problems with the BLOB column.
I have this bit of code:
cmd.CommandText = "select * from local_it.local_email_template where name = '" & cb_EmailName.Text & "'"
dr = cmd.ExecuteReader
dr.Read()
tb_Username.Text = dr.Item(1)
tb_Password.Text = dr.Item(2)
tb_FromName.Text = dr.Item(3)
tb_FromEmail.Text = dr.Item(4)
tb_Host.Text = dr.Item(5)
n_Port.Value = dr.Item(6)
cb_Action.Text = dr.Item(7)
tb_Subject.Text = dr.Item(8)
rtb_Body.Text = dr.Item(9)
dr.Close()
But I'm getting an error on the line rtb_Body.text = dr.item(9), saying
Conversion from type 'Byte()' to type 'String' is not valid
So I tried to say rtb_Body.text = dr.item(9).tostring, but now I just get the text
System.Byte[]
in my RichRextBox.
So my question is: How do I write this bit (or my query for that matter) so I get the actual text in my RichRextBox?
Working with Visual Studio 2012, VB.NET on an Oracle g11 Database
回答1:
You can use enconding functions from System.Text namespace:
for save in blob field:
Dim blob_bytes_to_db As Byte() = System.Text.Encoding.ASCII.GetBytes(RichTextBox1.Rtf)for load blob into richtextbox:
RichTextBox1.Rtf = System.Text.Encoding.ASCII.GetChars(blob_bytes_from_db)
Note: With RichTextBox1 .Text property can get/set clean text only. If you want to get/set formatted text with all RTF codes, use .Rtf property.
来源:https://stackoverflow.com/questions/33563778/oracle-blob-datatype-to-richtextbox