2012-07-24 3 views
0

현재 막혀있는 문제가 발생했습니다. 예 :linq 쿼리를 사용하여 열과 열 비교

EmployeeShiftID |  ShiftTime_Start  |  hiftTime_Stop  |  Name  | Emp_Start | Emp_Stop 
       |(linked with foreign key)| (linked with FK) |    |   | 
    1   |  0000    |   1000   |  Ken  | 0000 | 1000 

이러한 데이터는 외부 키가 연결된 데이터 격자보기로 표시됩니다. 그리고 시프트 시작과 멈춤도 Emp_Start와 일치하고 멈 춥니 다. 문제는 Emp_start를 업데이트하고 멈추었을 때 ShiftTime_Start 및 중지가 Emp_Start를 중단 한 것과 비교하지 않고 Emp_Start를 변경하고 0430 및 2100으로 변경하려고 시도했을 때 0000 및 1000으로 유지된다는 것입니다.

데이터베이스에 저장 한 시간 유형은 '시간'유형 대신 문자열입니다. 누구든지 저를 도울 수 있습니까? 나는 그것을 위해 한 모든 코드를 보여줄 것이다.

private void btnUpdate_Click(object sender, EventArgs e) 
{ 
    using (testEntities Setupctx = new testEntities()) 
    { 
     int ID = Int32.Parse(lblID.Text); 
     var ESquery = (from es in Setupctx.employeeshifts 
         where es.EmployeeShiftID == ID 
         select es).First(); 

     ESquery.StartTime = txtStart.Text; 
     ESquery.EndTime = txtStop.Text; 
     ESquery.Date = txtDate.Text; 
     Setupctx.SaveChanges(); 
     txtStart.Text = ""; 
     txtStop.Text = ""; 
     txtDate.Text = ""; 
     this.Edit_Employee_Shift_Load(null, EventArgs.Empty); 
     MessageBox.Show("Employee's Shift Has Been Updated."); 
    } 
} 


private void LoadAllEditEmpShift() 
{ 
    using (testEntities Setupctx = new testEntities()) 
    { 
     BindingSource BS = new BindingSource(); 
     var Viewemp = from ES in Setupctx.employeeshifts 
         join shifthour sh in Setupctx.shifthours on ES.ShiftHourID equals sh.idShiftHours 
         select new 
         { 
          ES.EmployeeShiftID, 
          ShiftHour_Start = sh.shiftTiming_start, 
          ShiftHour_Stop = sh.shiftTiming_stop, 
          ES.EmployeeName, 
          ES.StartTime, 
          ES.EndTime, 
          ES.Date 
         }; 

     BS.DataSource = Viewemp; 
     dgvEmpShift.DataSource = BS; 
    } 
} 

답변

1

나는이 다음과 같아야합니다 생각 :

private void btnUpdate_Click(object sender, EventArgs e) 
{ 
    using (testEntities Setupctx = new testEntities()) 
    { 
     int ID = Int32.Parse(lblID.Text); 
     var ESquery = (from es in Setupctx.employeeshifts 
         where es.EmployeeShiftID == ID 
         select es).First(); 
     var SHquery = (from sh in Setupctx.shifthours where sh.idShiftHours == ESQuery.ShiftHourID 
         select sh).First(); 

     ESquery.StartTime = txtStart.Text; 
     ESquery.EndTime = txtStop.Text; 
     ESquery.Date = txtDate.Text; 
     SHquery.shiftTiming_start = ESquery.StartTime; 
     SHquery.shiftTiming_stop = ESquery.EndTime; 
     Setupctx.SaveChanges(); 
     txtStart.Text = ""; 
     txtStop.Text = ""; 
     txtDate.Text = ""; 
     this.Edit_Employee_Shift_Load(null, EventArgs.Empty); 
     MessageBox.Show("Employee's Shift Has Been Updated."); 
    } 
} 
0

btnUpdate_Click 메서드에서 shifthours 개체의 속성을 암시 적으로 업데이트해야합니다.

+0

케어 나에게 몇 가지 예를 떠날? – Philemon