richtextbox 读取mysql中mediumblob数据问题

foxhunter5632 2012-07-22 12:56:56
这个是我的读出代码

private void dataGridView1_CellMouseDoubleClick(object sender, DataGridViewCellMouseEventArgs e)
{

id = this.dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString();
MySql.Data.MySqlClient.MySqlCommand cmd = new MySql.Data.MySqlClient.MySqlCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText = "select `data` from `test1`.`test` where `id`='"+id+"';";
System.IO.MemoryStream ms = Mysqlconn.getmemory(cmd);
this.richTextBox1.LoadFile(ms, RichTextBoxStreamType.RichText);

}

这是getmemory(cmd)

public static MemoryStream getmemory(MySqlCommand cmd)
{
int re = 0;
MySqlConnection mycon = Mysqlconn.mysqlconn(ref re);

try
{
mycon.Open();
cmd.Connection = mycon;
DbDataReader reader = cmd.ExecuteReader();
reader.Read();
long len = reader.GetBytes(0, 0, null, 0, 0);
byte[] buffer = null;
buffer = new byte[len];
System.IO.MemoryStream mstream = new System.IO.MemoryStream(buffer);
return mstream;
}
finally
{
mycon.Close();
}

}

问题来了,现在用getmemory方法获得的mstream数据全0,调试发现len获取的数据全0,导致最后加入到richtextbox的数据格式不对并报错。数据库里的我都看过了,并非全0数据。我估计大概reader.getbytes()有点问题,请高手指导一下。
...全文
128 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
foxhunter5632 2012-11-23
  • 打赏
  • 举报
回复
大概是太简单了,都没人回复。我也找到原因了,如果谁有碰到相同问题的,可以cal我

110,532

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧