如何从数据库中检查用户的登录时间? [英] How to check login time of user from database?
问题描述
我想在数据库中保存用户的登录和注销时间。我能够节省登录时间。我想如果用户已经登录,则在整个特定日期不应该有重复的条目。以下是我的sql编码和c#编码可以任何一个帮助我..
提前预付
我的sql表结构如下
< pre lang =SQL> create table EmpAttendance
(
AttendenceID int primary key ,
EmpID < span class =code-keyword> nvarchar ( 10 ) foreign key 参考员工(EmpID),
LoginTime datetime ,
LogoutTime datetime ,
AttDate datetime
)
和C#编码是..
DataSet ds1 = obj.CheckAttendance(Session [ EmpID]。ToString(),(DateTime.Now).ToString());
if (ds1.Tables [ 0 ]。Rows.Count > 0 )
{
/ / Response.Write(hiiiiii);
}
else
{
obj.InsAttendance(会话[ EmpID]。 ToString(),(DateTime.Now).ToString(), ,(DateTime.Now)的ToString());
// Response.Write(hiiiiii);
}
每次只有其他部分正在运行.....我希望其他部分只在没有条目时运行.....
添加预
标签。
[/编辑]
那是因为你正在检查(DateTime.Now).ToString()
,这将是总是不同,因为它是DateTime
值,而不仅仅是日期
。
要仅获得日期
,您只需存储日期
并进行比较。
您可以使用DateTime.Now.ToString(M / d / yyyy);
。
但请确保在存储时,您还以此格式存储日期
。
了解更多关于格式,请参阅 - 自定义日期和时间格式字符串 [ ^ ]。
I want to save login and logout time of user in the databse.I am able to save login time.I want if user has logged in once there should not be duplicate entry on whole particular date. following are my sql coding and c# coding can any one help me..
thanx in advance
my sql table structure is as follows
create table EmpAttendance
(
AttendenceID int primary key ,
EmpID nvarchar(10) foreign key references Employee(EmpID),
LoginTime datetime,
LogoutTime datetime,
AttDate datetime
)
And C# coding are..
DataSet ds1 = obj.CheckAttendance(Session["EmpID"].ToString(), (DateTime.Now).ToString());
if (ds1.Tables[0].Rows.Count > 0)
{
//Response.Write("hiiiiii");
}
else
{
obj.InsAttendance(Session["EmpID"].ToString(), (DateTime.Now).ToString(), "", (DateTime.Now).ToString());
// Response.Write("hiiiiii");
}
every time only else part is running.....i want that else part should run only when there is no entry.....
[Edit member="Tadit"]
Added pre
tags.
[/Edit]
That is because you are checking with(DateTime.Now).ToString()
, which will be different always as it is aDateTime
value, notDate
only.
To getDate
only, you have to store theDate
only and compare that.
You can useDateTime.Now.ToString("M/d/yyyy");
.
But make sure, while storing, you also storeDate
in this format.
To know more on formats, see - Custom Date and Time Format Strings[^].
这篇关于如何从数据库中检查用户的登录时间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!