I have a problem adding data to the database. The code I have written can change shifting_start only the change, but the change Is not Timing_Stop Anyone please take a look at my code and see what went wrong. Thanks a lot.
private void using btnUpdate_Click (Object Sender, EventArgs E) {{testEntities Setupctx = new testEntities ()) {var toBeUpdated = txtStart.Text; Var toBeUpdated1 = txtStop.Text; Shifthour updateShift = new shifthour (); UpdateShift = Setupctx.shifthours.FirstOrDefault (U = & gt; u.shiftTiming_start == toBeUpdated); UpdateShift = Setupctx.shifthours.FirstOrDefault (p = & gt; p.shiftTiming_stop == toBeUpdated1); UpdateShift.shiftTiming_start = txtStart.Text; UpdateShift.shiftTiming_stop = txtStop.Text; Setupctx.SaveChanges (); TxtStart.Text = ""; TxtStop.Text = ""; MessageBox.Show ("Shift Time has been updated."); Let's say I'm following you correctly (I can recommend using more meaningful variables)), update the code as follows: Private zero btnUpdate_Click (object) Sender, EventArgs e) {using (testEntities Setupctx = new testEntities ()) {var toBuUpdatedStart = txtStart.Text; Var toBeUpdatedStop = txtStop.Text; Shifthour update startshift; Move; UpdateStartShift = Setupctx.shifthours.FirstOrDefault (U = & gt; u.shiftTiming_start == toBeUpdatedStart); UpdateStopShift = Setupctx.shifthours.FirstOrDefault (p = & gt; p.shiftTiming_stop == toBeUpdatedStop); If (updateStartShift! = Null) {updateStartShift.shiftTiming_start = txtStart.Text; } If (updateStopShift! = Null) {updateStopShift.shiftTiming_stop = txtStop.Text; } Setupctx.SaveChanges (); TxtStart.Text = ""; TxtStop.Text = ""; MessageBox.Show ("Shift Time has been updated."); }}
Comments
Post a Comment