1 将RichTextBox的内容直接写入数据库: 2 private void button1_Click(object sender, EventArgs e) 3 { 4 System.IO.MemoryStream mstream = new System.IO.MemoryStream(); 5 this.richTextBox1.SaveFile(mstream, RichTextBoxStreamType.RichText); 6 //将流转换成数组 7 byte[] bWrite = mstream.ToArray(); 8 //将数组写入数据库 9 System.Data.SqlClient.SqlParameter[] pram ={ 10 sqlHelper.MakeInParam("@XX",System.Data.SqlDbType.Image) 11 }; 12 pram[0].Value = bWrite; 13 sqlHelper.RunSql("insert into XXX (XX) values (@XX)", pram); 14 } 15 将数据库中的RTF读出并填充到RichTextBox 16 private void button2_Click(object sender, EventArgs e) 17 { 18 //从数据库中读出数据 19 DataTable dt=sqlHelper.GetDataTable("select XX from XXX where ....."); 20 byte[] bWrite = (byte[])dt.Rows[0][0]; 21 //将数组转换成stream 22 System.IO.MemoryStream mstream = new System.IO.MemoryStream(bWrite, false); 23 //将stream填充到RichTextBox 24 this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText); 25 }