Microsoft Developer Network > 포럼 홈 > Visual C# General > getting binary data out of the database
질문하기질문하기
 

제안된 답변getting binary data out of the database

  • 2009년 11월 7일 토요일 오전 10:19Mitja Bonca 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    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?

모든 응답

  • 2009년 11월 7일 토요일 오후 5:59technocrat_aspire 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     
    Can you post the code to get the binary data as well? How are you retrieving it?
  • 2009년 11월 7일 토요일 오후 6:31Mitja Bonca 사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     코드 있음
    This is my code:

     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();
    
    This is my exact code which gets the binary data out of the database.
  • 2009년 11월 10일 화요일 오후 12:50Roahn LuoMSFT, Moderator사용자 메달사용자 메달사용자 메달사용자 메달사용자 메달
     제안된 답변
    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!