c# - How to update the item of the listbox as well as in the iso store local database -


as working on how update data in local database in windows phone app problem facing item want edit not edited , second item created in database due code want edit , update same data item without creating second item in database. please me how update item in database..

my view model:

public void getpersonallist() {    try    {       personaldatacontext addreminder = new personaldatacontext(personaldatacontext.dbconnectionstring);       if (addreminder.personal.count() > 0)       {          this.personallist.clear();          personalreminderdata reminderdata = new personalreminderdata();          list<personaltable> personals = reminderdata.getreminderdata();          foreach (var personalitem in personals)          {             this.personallist.add(new personalmodel             {                id = personalitem.id,                title = personalitem.title,                description = personalitem.description,                date = personalitem.date,                time = personalitem.time             });          }       }          else personallist.clear();    }    catch    { } }  public bool remindersavedetail(personalmodel personalmodel) {    bool result = false;    if (iseditmode)    {       personalreminderdata personalsaveeditdata = new personalreminderdata();       result = personalsaveeditdata.editpersonalreminder(personalmodel);       iseditmode = false;    }    else    {       personalreminderdata personalsavedata = new personalreminderdata();       result = personalsavedata.addpersonalreminder(personalmodel);    }    return result; }  public void cleardata() {    this.personalmodel.title = string.empty;    this.personalmodel.description = string.empty;    this.personalmodel.date = datetime.today.date;    this.personalmodel.time = datetime.now.timeofday.tostring(); }  public void editreminder(int id) {    if (messageboxresult.ok == messagebox.show("this let edit reminder,continue?", "edit", messageboxbutton.okcancel))    {       navigationservice.navigatetopage(views.mainpage, enumforview.mainpage);       this.personalmodel = (from personalitem in personallist personalitem.id == id select personalitem).firstordefault();    } } 

this database class:

public  bool editpersonalreminder(personalmodel personalmodel) {    try    {       using (personaldatacontext addreminder = new personaldatacontext(personaldatacontext.dbconnectionstring))       {          personaltable reminderdetail = new personaltable();           //var personalmodel = (from personalitem in addreminder.personal personalitem.id == personalmodel.id select personalitem).firstordefault();          reminderdetail.id = personalmodel.id;          reminderdetail.title = personalmodel.title;          reminderdetail.description = personalmodel.description;          reminderdetail.date = personalmodel.date;          reminderdetail.time = personalmodel.time;          addreminder.personal.insertonsubmit(reminderdetail);          addreminder.submitchanges();          return true;       }    }    catch    {       return false;    }         }  public bool deletepersonalreminder(int id) {    try    {       using (personaldatacontext addreminder = new personaldatacontext(personaldatacontext.dbconnectionstring))       {          var deletedetailobj = (from personalitem in addreminder.personal personalitem.id == id select personalitem).firstordefault();          addreminder.personal.deleteonsubmit(deletedetailobj);          addreminder.submitchanges();          return true;       }    }    catch    {       return false;    } }  public list<personaltable> getreminderdata() {    using (personaldatacontext addreminder = new personaldatacontext(personaldatacontext.dbconnectionstring))    {       var reminderdata = (from personalitem in addreminder.personal orderby personalitem.id descending select personalitem ).tolist();       return reminderdata;    } } 

why have line addreminder.personal.insertonsubmit(reminderdetail); in editpersonalreminder method? insert new item everytime. need item db (for example id), make changes , call submitchanges on datacontext.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -