我是wpf的新手,我想將格式(斜體,彩色,粗體..)的富文本框的數據與其格式(斜體,彩色,粗體..)一起存儲到數據庫(Mysql)中。 當前當我保存數據時,格式將被忽略。 此外,當我將它加載回數據庫的富文本框時,它顯示了同一行中的所有文本。 期待您的幫助和建議!將格式化富文本框的數據存儲到數據庫
public void save()
{
MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand command = conn.CreateCommand();
string richText = new TextRange(rt1.Document.ContentStart, rt1.Document.ContentEnd).Text;
string s = WebUtility.HtmlEncode(richText);
command.Parameters.AddWithValue("@s", s);
command.CommandText = "insert into proc_tra (procedures) values (@s)";
conn.Open();
command.ExecuteNonQuery();
conn.Close();
}
public void load()
{ MySqlConnection conn = new MySqlConnection(connString);
MySqlCommand command = conn.CreateCommand();
command.CommandText = "select * from proc_tra where id_pt=4";
rt1.Document.Blocks.Clear();
conn.Open();
MySqlDataReader dr;
dr = command.ExecuteReader();
string k="";
while (dr.Read())
{
k += dr["procedures"].ToString();
}
var p = new Paragraph();
var run = new Run();
run.Text = WebUtility.HtmlDecode(k);
p.Inlines.Add(run);
rt1.Document.Blocks.Add(p);
}
hope [this](http://www.codeguru.com/columns/dotnettips/article.php/c7529/Saving-Rich-Edit-Control-Text-to-SQL-Server.htm)幫助 – Pyromancer