sql - Richtextbox Append Query C# -


i having trouble in getting database updated using c# form. using 2 richtextboxes, 1 read , contain data has been retrieved database (richtextbox). other richtextbox used allow data input database (richtextbox1). when form loads, data database loaded read textbox. data can written richtextbox1 appended database once have pressed 'edit' button.

the problem having instead of appending data database, new data entered overwriting old data. seems sources have read, there no way of appending data, replacing data. code follows:

code retrieve data database:

private void quizform_load(object sender, eventargs e)         {         //declare connection string using windows security         string cnstring = "provider=microsoft.ace.oledb.12.0;data source=c:\\users\\hannah\\desktop\\quiz.accdb";          //declare connection, command , other related objects         oledbconnection conget = new oledbconnection(cnstring);         oledbcommand cmdget = new oledbcommand();          try         {             //open connection             conget.open();              cmdget.commandtype = commandtype.text;             cmdget.connection = conget;             cmdget.commandtext = "select datatoread quizquestions";              richtextbox.text = cmdget.executescalar().tostring();              conget.close();          } 

code save data database:

private void btnedit_click(object sender, eventargs e)         {             //richtextbox.enabled = true;              {             //declare connection string using windows security             string cnstring = "provider=microsoft.ace.oledb.12.0;data source=c:\\users\\hannah\\desktop\\quiz.accdb";              //declare connection, command , other related objects             oledbconnection consave = new oledbconnection(cnstring);             oledbcommand cmdsave = new oledbcommand();              try             {                  //open connection                 consave.open();                  cmdsave.commandtype = commandtype.text;                 cmdsave.connection = consave;                 cmdsave.commandtext = "update quizquestions set datatoread = @prichtextbox";                   oledbparameter parrichtextbox1 = new                    oledbparameter("@prichtextbox", oledbtype.varchar);                 parrichtextbox1.value = (richtextbox.text + richtextbox1.text);                  cmdsave.executenonquery();                  //cmdsave.parameters.add("@parrichtextbox1", oledbtype.varchar, combinedtextbox);                  consave.close();                 //end of code               } 

in summary, happen: 1. form opens, , automatically richtextbox populated database contents 2. data/text entered in richtextbox1, 'edit' button pressed, resulting in data being appended database. 3. when form reopened, data added visible in read-only textbox richtextbox

your sql statement indeed overwriting data. if you'd append data exists in richtextbox record has been read db, update sql statement should this:

update quizquestions set datatoread = datatoread + @prichtextbox 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -