如何在sql中设置位true [英] how to set bit true in sql

查看:124
本文介绍了如何在sql中设置位true的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有网页表格并正确插入数据。对于一名员工,我在表格中有多条记录。

 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已尝试所有最后和默认方法,orderby等,但结果正常。因为对一名员工有不同的状态和不同的职责类型,所以我有一个想法,我在该表中添加一个新的列,这是一个类型,当我插入新的记录对该员工位设置为真的最后一个记录和以前的记录被设置为假>>该怎么样的出租车是使用c#完成。

解决方案

如果我理解你的问题,在我看来这将是一个糟糕的设计。



相反,您应该拥有具有非特定时间属性的员工表。列,如Id,名称等。



然后你应该有一个子表,其中应该包含Type,Status以及随时间变化的内容。此表应至少有一列定义行上状态变为有效的时刻。这样,您只需向表中添加新行,这些新行在逻辑上使指定员工的旧行无效。



类似

< pre lang =text> EmployeeStatus
--------------
- EmployeeId int
- 类型int
- 状态int
- ValidFrom datetime


你仍然需要主键,让它成为Status_Id。如果它是一个自动增量字段,您可以选择具有该特定Employee_Id的Status_Id最高的记录,您将获得最新的记录。



[更新]

这里描述了如何按行组排名最高。在这种情况下,raking是Status_Id,分组条件是Employee_Id,按状态过滤: https://smehrozalam.wordpress.com/2009/12/29/linq-how-to-get-the-latest-last-记录与分组/ [ ^ ]


i have web form and data is inserted properly.against one employee i have multiple records in the table.

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#.

解决方案

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


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/[^]


这篇关于如何在sql中设置位true的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆