private void btnUpdate_Click(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
var toBeUpdatedStart = txtStart.Text;
var toBeUpdatedStop = txtStop.Text;
shifthour updateShiftStart;
shifthour updateShiftStop;
updateShiftStart = Setupctx.shifthours.FirstOrDefault(u => u.shiftTiming_start == toBeUpdatedStart);
updateShiftStop = Setupctx.shifthours.FirstOrDefault(p => p.shiftTiming_stop == toBeUpdatedStop);
updateShiftStart.shiftTiming_start = txtStart.Text; <-- error prompt here
updateShiftStop.shiftTiming_stop = txtStop.Text;
Setupctx.SaveChanges();
txtStart.Text = "";
txtStop.Text = "";
MessageBox.Show("Shift Timing Has Been Updated.");
}
}
Hi, anyone have any idea what’s wrong with this code?
More information :
This is to edit shift hours for staff. When I entered the new start and stop time, the error prompt out and say “Object reference not set to an instance of an object.”
private void btnUpdate_Click(object sender, EventArgs e)
{
using (testEntities Setupctx = new testEntities())
{
int ID = Int32.Parse(lblID.Text);
var SHquery = (from sh in Setupctx.shifthours
where sh.idShiftHours == ID
select sh).First();