码迷,mamicode.com
首页 > 数据库 > 详细

将RichTextBox的内容直接写入数据库:

时间:2014-06-19 08:02:02      阅读:244      评论:0      收藏:0      [点我收藏+]

标签:class   blog   http   tar   ext   com   

将RichTextBox的内容直接写入数据库:
private void button1_Click(object sender, EventArgs e)
{
   System.IO.MemoryStream mstream = new System.IO.MemoryStream();
   this.richTextBox1.SaveFile(mstream, RichTextBoxStreamType.RichText);
   //将流转换成数组
   byte[] bWrite = mstream.ToArray();
   //将数组写入数据库
   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);
}

将数据库中的RTF读出并填充到RichTextBox
private void button2_Click(object sender, EventArgs e)
{
   //从数据库中读出数据
   DataTable dt=sqlHelper.GetDataTable("select XX from XXX where .....");
   byte[] bWrite = (byte[])dt.Rows[0][0];
   //将数组转换成stream
   System.IO.MemoryStream mstream = new System.IO.MemoryStream(bWrite, false);
   //将stream填充到RichTextBox
   this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
}

将RichTextBox的内容直接写入数据库:,布布扣,bubuko.com

将RichTextBox的内容直接写入数据库:

标签:class   blog   http   tar   ext   com   

原文地址:http://www.cnblogs.com/wangchuang/p/3789410.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
分享档案
周排行
mamicode.com排行更多图片
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!