Click here to Skip to main content
15,884,388 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have web form and data is inserted properly.against one employee i have multiple records in the table.
C#
EmployeeStatus empStatus = new EmployeeStatus();
              empStatus.Employee_Id = Employee.Id;
              empStatus.EmployeeStatusType_Id = SafeConvert.ToByte(ddlEmpStatus.SelectedValue);
              empStatus.StartDate = SafeConvert.ToDateTime(txtStartDate.Text);
              empStatus.EndDate = SafeConvert.ToDateTime(txtEndDate.Text);
              empStatus.Sector_Id = SafeConvert.ToByte(ddlSelectSector.SelectedValue);
              empStatus.Rank_Id = SafeConvert.ToByte(ddlRank.SelectedValue);
              empStatus.IsDutiable = txtIsDutiable.Checked;
              empStatus.HasWirles = txtHasWirles.Checked;
              empStatus.DutyType_Id = SafeConvert.ToByte(ddlDutyType.SelectedValue);
              empStatus.EmployeeShift_Id = SafeConvert.ToByte(ddlEmployeeShift.SelectedValue);
              _service.InsertEmployeeStatus(empStatus);
              _queryStatus = empStatus.Id > 0;

i have tried all last&default method,orderby,etc but result is getting properly.because against one employee there are different status and different duty type, so i got one idea that i add a new column in that table which is a bit type,and when i insert new record against that employee bit is set true for that last record and for previous records is set false>>how that cab be done using c#.
Posted

If I understood your question correctly, in my opinion that would be a bad design.

Instead you should have employee table having the attributes that are not "time specific". Columns like Id, name and so on.

Then you should have a child table which should contain the Type, Status and whatever may be changed over time. This table should have at least one column defining the moment when the status on the row became valid. This way you only add new rows to the table and these new rows logically invalidate older rows for the specified employee.

Something like
EmployeeStatus
--------------
- EmployeeId int
- Type       int
- Status     int
- ValidFrom  datetime
 
Share this answer
 
Comments
Sajid227 23-Jan-15 14:51pm    
i am using your option and storing record in these table,but i am getting record from this table EmployeeStatus,then retrive info and save this info into other record,problem is that there are a number of record against same employee,that same employee then repeated in different status,i just want that if just got last record then duplication will be end
Wendelius 23-Jan-15 14:56pm    
In that case your select should be something like
select ...
from employee e, employeestatus es
where e.employeeid = es.employeeid
and not exists
( select 1
from employeestatus es2
where es2.employeeid = es.employeeid
and es2.validfrom > es.validfrom)
You still need primary key, let it be Status_Id. If it is an autoincrement field, you can select the record with the highest Status_Id for that specific Employee_Id, you get the latest.

[update]
Here is described how you can get highest ranked by group of rows. In this case, the raking is the Status_Id, and the grouping criteria is Employee_Id, filtered by Status: https://smehrozalam.wordpress.com/2009/12/29/linq-how-to-get-the-latest-last-record-with-a-group-by-clause/[^]
 
Share this answer
 
v3
Comments
Sajid227 23-Jan-15 14:37pm    
but problem is that i have to get all the employee having same status,so i want to get last record against each employee of same status
Zoltán Zörgő 23-Jan-15 14:59pm    
See update

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900