这个是我的读出代码 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()有点问题,请高手指导一下。
{ 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()有点问题,请高手指导一下。
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货