lc304416870 2014-12-07 09:01 采纳率: 0%
浏览 3369

c# richtext存入文字+图片至数据库,读取时报文件格式无效错误

//将richtext中文字+图片存入数据库
this.rtbText.SaveFile(mstream, RichTextBoxStreamType.RichText);
mstream.Position = 0;
 SqlCommand cmd = new SqlCommand();
 System.Data.SqlClient.SqlParameter[] pram = new System.Data.SqlClient.SqlParameter[] { };
 cmd.Parameters.AddWithValue("@project_content",mstream.ToArray());
string sql = "insert into project values('" + cbbHospotal.Text + "','" + cbbType.Text + "','@project_content','未确认','待开发','','" + AllStatic.userName + "',getdate(),'','" + label2.Text + "')";
 int i = sl.ExecuteNonQuery(sql,pram,CommandType.Text);

//从数据库读取至richtext
 byte[] bWrite = (byte[])(dt.Rows[0]["project_content"]);

 if (bWrite != null)
 {
 using ( MemoryStream mstream = new MemoryStream())
 {
mstream.Write(bWrite, 0, bWrite.Length);
mstream.Position = 0;
//将stream填充到RichTextBox
this.richTextBox1.LoadFile(mstream, RichTextBoxStreamType.RichText);
                   } }

报错,文件格式无效

  • 写回答

1条回答 默认 最新

  • q107770540 2014-12-07 09:04
    关注

    debug一下,看一下从数据库取出的数据是什么格式的

    评论

报告相同问题?

悬赏问题

  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 display:none;样式在嵌套结构中的已设置了display样式的元素上不起作用?
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
  • ¥50 树莓派安卓APK系统签名
  • ¥65 汇编语言除法溢出问题