zoukankan      html  css  js  c++  java
  • 将RichTextBox的内容直接写入数据库:

     

     

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

  • 相关阅读:
    WPF元素之间的关系
    依赖属性
    多线程显示运行状态
    WPF 基本知识
    SQL 这个删除重复行怎么做
    路由事件
    WPF的数据邦定
    SQL对表中XML列的查询
    WMI访问注册表读取系统信息
    创建第一个WPF应用程序
  • 原文地址:https://www.cnblogs.com/wangchuang/p/3789410.html
Copyright © 2011-2022 走看看