Write the contents of the RichTextBox directly to the database:

Source: Internet
Author: User

Write the contents of the RichTextBox directly to the database:
private void Button1_Click (object sender, EventArgs e)
{
System.IO.MemoryStream mstream = new System.IO.MemoryStream ();
This.richTextBox1.SaveFile (Mstream, Richtextboxstreamtype.richtext);
Change the flow to an array
byte[] Bwrite = Mstream. ToArray ();
Write an array to the database
System.data.sqlclient.sqlparameter[] Pram ={
Sqlhelper.makeinparam ("@XX", System.Data.SqlDbType.Image)
};
Pram[0]. Value = Bwrite;
Sqlhelper.runsql ("INSERT into XXX (XX) VALUES (@XX)", pram);
}

The RTF in the database is read out and populated to RichTextBox
private void button2_click (object sender, EventArgs e)
{
  // Read data from the database
   DataTable dt=sqlhelper.getdatatable ("Select XX from XXX where ...");
   byte[] Bwrite = (byte[]) dt. ROWS[0][0];
  //Convert an array to stream
   System.IO.MemoryStream mstream = new System.IO.MemoryStream (Bwrite, FALSE);
  //fill stream into RichTextBox
   This.richTextBox1.LoadFile (Mstream, Richtextboxstreamtype.richtext);
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.