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);
}