RichTextBox.RTF not accepting String generated from Database - C# -


i have bit of weird problem here. i'm attempting create form that, when making selection listbox, poll data database , display in richtextbox. need data in rtf formatting purposes.

it works fine if this:

    private void savelisttest_selectedindexchanged(object sender, eventargs e)     {         descriptionname = convert.tostring(savelisttest.selecteditem);         //calldescriptiontest();         calldescriptiontest2();         saverichtest.rtf = descriptiontext;     }      public void calldescriptiontest2()     {         switch (descriptionname)         {             case "test":                 descriptiontext = @"{\rtf1\ansi\ test}";                 break;             case "words":                 descriptiontext = @"{\rtf1\ansi\ long phrase}";                 break;         }     } 

in such case, richtextbox (saverichtest) take data , display fine.

however, if this, description column in database has text entered above (ex - @"{\rtf1\ansi\ test}"):

    private void savelisttest_selectedindexchanged(object sender, eventargs e)     {         descriptionname = convert.tostring(savelisttest.selecteditem);         calldescriptiontest();         //calldescriptiontest2();         saverichtest.rtf = descriptiontext;     }      public void calldescriptiontest()     {         using (sqlconnection con = new sqlconnection(builddb))         {             con.open();             string sql = string.format("select * abilities name = '{0}'", descriptionname);             sqlcommand ocmd = new sqlcommand(sql, con);              using (sqldatareader oreader = ocmd.executereader())             {                 while (oreader.read())                 {                     descriptiontext = convert.tostring(oreader["description"]);                 }                 con.close();             }         }     } 

this instead cause program crash, error "file format not valid".

i know text pulling database correctly, because if change "saverichtest.rtf" "saverichtest.text", displays (albeit rtf formatting code displayed).

i can't figure out why won't take string in second case. makes no sense me whatsoever. can help?

i guess in case when tried show output in plain text output was: @"{\rtf1\ansi\ test}

this mean when want show string formatted directly database pass "@"{\rtf1\ansi\ test}"" instead of correct format. i'd suggest store format without @ in database , show result.


Comments

Popular posts from this blog

get url and add instance to a model with prefilled foreign key :django admin -

css - Make div keyboard-scrollable in jQuery Mobile? -

ruby on rails - Seeing duplicate requests handled with Unicorn -