保存到数据库的内容:
byte[] b=System.Text.Encoding.Default.GetBytes(this.richTextBox1.Rtf);
读取:
SqlConnection con=new SqlConnection("...");
string str="select 内容 from 数据库 where ...";//确保只返回一行
SqlCommand comm=new SqlCommand(str,con);
if (con.State==ConnectionState.Closed)
con.Open();
byte[] b=(byte[])comm.ExecuteScalar();
MemoryStream stream=new MemoryStream(b,true);
stream.Write(b,0,b.Length);
this.richTextBox1.Clear();
string s=System.Text.Encoding.Default.GetString(b,0,b.Length);
this.richTextBox1.Rtf=@s;
stream.Close();以上这段代码看了很长时间,不知道定义一个内存流的用途是什么,我试着按上面说法将richtextbox中的图文混排内容保存到数据库中,可是读取的时候说是类型不匹配,数据库中是备注型字段,望高手指点!!!
byte[] b=System.Text.Encoding.Default.GetBytes(this.richTextBox1.Rtf);
读取:
SqlConnection con=new SqlConnection("...");
string str="select 内容 from 数据库 where ...";//确保只返回一行
SqlCommand comm=new SqlCommand(str,con);
if (con.State==ConnectionState.Closed)
con.Open();
byte[] b=(byte[])comm.ExecuteScalar();
MemoryStream stream=new MemoryStream(b,true);
stream.Write(b,0,b.Length);
this.richTextBox1.Clear();
string s=System.Text.Encoding.Default.GetString(b,0,b.Length);
this.richTextBox1.Rtf=@s;
stream.Close();以上这段代码看了很长时间,不知道定义一个内存流的用途是什么,我试着按上面说法将richtextbox中的图文混排内容保存到数据库中,可是读取的时候说是类型不匹配,数据库中是备注型字段,望高手指点!!!
stream.Write(b,0,b.Length);
多余的把...string s=System.Text.Encoding.Default.GetString(b,0,b.Length);
获取了RTF 没必要使用STREM了