getting binary data out of the database
- I am doing an app which inclueds richTextBox, for inserting text. I put some text into richTextBox and save it into my sql database (column is varbinary(MAX) data type, with this code
byte[] myFile = Encoding.UTF8.GetBytes(richTextBox1.Text);Here the text is changed into binary data, and them I add parameters and all whats needed, and finally:cmd1.ExecuteNonQuery();
Then, when I want to open it, it opens in word (the code is made, that it opens in this program - depending on an extention and a file type).So, when the Word is starting up, 1st it asks me if I want to change it (to use some other coding). I select nothing and click Ok. The text is there but it is not in the shape I inserted it into richTextBox. The font are all the same and are in Courier New (I didn`t save the the text in with this font, and even the text was not all the same).Anyone has any clue how to get the same text out, as I saw inserted into richTextBox? Is this maybe anything to do with richTextBox, or this is only a matter of coding?
全部回复
- Can you post the code to get the binary data as well? How are you retrieving it?
- This is my code:This is my exact code which gets the binary data out of the database.
povezava.Open(); string dobiVsebino = "SELECT VsebinaO FROM Obvestilo WHERE ImeO = '" + listView1.SelectedItems[0].Text + "'"; SqlCommand cmd1 = new SqlCommand(dobiVsebino, povezava); byte[] buffer = (byte[])cmd1.ExecuteScalar(); povezava.Close(); - Hello,
I'm not sure how did you open it in a word, have you tried encoding the byte array into a string and then display?
String myText = Encoding.UTF8.GetString(buffer);
this.richTextBox1.Text = myText;
Please let me know if this helps.
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
If you have any feedback, please tell us.
Welcome to the All-In-One Code Framework!- 已建议为答案Roahn LuoMSFT, 版主2009年11月13日 5:25

