c# - Trying to update a record, but the update code only updates one of the timestamp fields and nothing else -


i have database table need update records on. code add new record works fine, when go update existing record, not fields update new information in form.

here's code:

    private void updateexistingdsn()     {         //update existing dsn         try         {             using (pathfinderdatacontext pfdccontext = new pathfinderdatacontext())             {                 dsn olddsn = pfdccontext.dsns.single(dsn => dsn.dsnid == int.parse(request["dsn"]));                  olddsn.auth_authorizationid = int.parse(request["auth"]);                 olddsn.serviceprovided_serviceprovidedid = int.parse(request["sp"]);                 olddsn.evidencebpmu = short.parse(ddlevidencebpmu.selectedvalue);                 olddsn.locationofvisit = txtlocationofvisit.text;                 olddsn.childrenpresent = txtnamesofchildrenpresent.text;                 olddsn.parentpresent = txtnamesofparentspresent.text;                 olddsn.otherspresent = txtnamesofotherspresent.text;                 olddsn.describegoals = txtdescribegoals.text;                 olddsn.describestrategy = txtdescribestrategies.text;                 olddsn.descibeparentingskills = txtdescribeparentingskills.text;                 olddsn.describesafetyconcerns = txtdescribesafetyconcerns.text;                 olddsn.otherinfo = txtotherinfo.text;                 olddsn.schedule_monday = float.parse(txtmonday.text);                 olddsn.schedule_tuesday = float.parse(txttuesday.text);                 olddsn.schedule_wednesday = float.parse(txtwednesday.text);                 olddsn.schedule_thursday = float.parse(txtthursday.text);                 olddsn.schedule_friday = float.parse(txtfriday.text);                 olddsn.schedule_saturday = float.parse(txtsaturday.text);                 olddsn.schedule_sunday = float.parse(txtsunday.text);                 olddsn.datesaved = datetime.now;                 olddsn.savedby_userid = currentemployee.employeeid;                 pfdccontext.submitchanges();             }              response.redirect("~/pages/updatetimesheet.aspx?action=update&providedserviceid=" + int.parse(request["sp"]));         }         catch (exception ex)         {             errormessage.text = "<b>error updating existing dsn record!</b><br /><br />" + ex.tostring();             warnings.visible = true;         }     } 

the field updates olddsn.datesaved, else stays same. no errors or exceptions thrown or anything. acts works, doesn't. also, when hardcode values updated, record updates fine. ideas?

in page_load (where put information datasource textboxes, etc) need wrap databinding code in if(page.ispostback) block.

so code should this:

protected void page_load (object sender, eventargs e) {     if(!page.ispostback)     {         // whatever use load data database          // server controls goes here         loaddata(); // example     } } 

this why you're not getting updated information - markup elements being reloaded database before update code has chance run.


Comments

Popular posts from this blog

c++ - Creating new partition disk winapi -

Android Prevent Bluetooth Pairing Dialog -

php - joomla get content in onBeforeCompileHead function -