如何显示用户的首次登录时间?

编程入门 行业动态 更新时间:2024-10-24 08:20:15
本文介绍了如何显示用户的首次登录时间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

大家好, 我正在SQL Server 2008和asp平台上工作.我的项目有一个按钮,单击该按钮即可显示用户的登录时间. 我需要这样一个代码,当用户在同一天第二次登录时,我们必须显示一个标签,显示您已登录于",并显示一个文本框,显示该日的首次登录时间.另外,该按钮也应在页面上禁用. 关于此的任何帮助将非常有用. 谢谢.

Hi to all, I m working in SQL server 2008 and asp platform. My project has a button which on being clicked, shows the login time of the user. I need a code as such that when the user logs in for the second time on the same day we have to display a label showing "You have logged in at" and a textbox displaying the first login time for that day. Also the button should be disabled on the page. Any help regarding this would be very useful. Thank you.

推荐答案

您应该具有Logindetails表. 您可以通过两种方式进行操作 第一种方式 每次用户登录时插入新记录,并获取特定日期的分钟(时间). 这是一种历史,因此您可以跟踪每次登录 第二种方式: 用户当天首次登录时插入新记录.如果用户尝试第二次登录,请去检查该特定日期和特定用户的记录是否已存在.如果存在,请不要插入. 因此,现在每个用户每天只有一个登录时间.没有历史记录跟踪. You should have Logindetails table. You can do this in 2 way First way Insert new record everytime the user logins and get the min(time ) for that particular day. This is kind of history so you can keep track of every login Second way: Insert new record when user logins first time for the day. If user tries to login second time, go and check whether a record already exists for that particular day and for particular user . If it exists dont insert. So now you will have only one login time per day per user. No history tracking. if not exists(select 1 from logintable where CONVERT(varchar(8), logindate, 112) =CONVERT(varchar(8), GETDATE(), 112) and Id=1) insert into logintable(col1,col2,col3,logindate) values (val1,val2,val3,getdate())

根据评论更新了解决方案.

updated solution, based on the comments.

protected void Button2_Click(object sender, EventArgs e) { string intime = DateTime.Now.ToString(); string ID = Session["Name"].ToString(); string indate = DateTime.Now.ToShortDateString(); SqlConnection cn = new SqlConnection("Data Source=Sony-VAIO\\MSSQLSERVER2008;InitialCatalog=db;Integrated Security=True"); cn.Open(); SqlCommand cmd = new SqlCommand(@"if not exists (select 1 from intime where convert(varchar(30),indate,112)=convert(varchar(30),getdate(),112) and Id=@Id) insert into intime values ('" + ID + "','" + intime + "','" + indate + "')", cn); cmd.Parameters.AddWithValue("@Id", ID); cmd.ExecuteNonQuery(); cn.Close(); }

步骤1: 在每次登录时更新ur表,logtime列 步骤2: 将该日期与当前日期进行比较, 如果与检索日期和时间匹配,并显示在文本框中 也禁用按钮 否则, 什么都不检索 step 1: update ur table, logtime column on every login step 2: compare that date with the current date, if it matches retrive date and time and show it in textbox also disable the button otherwise, retrieve nothing

您可以将首次登录时间存储在数据库中. 以下是一些示例- 跟踪用户在您网站上的登录/注销时间 [ ^ ] www.4guysfromrolla/articles/081507-1.aspx [ ^ ] You can store the first login time in a database. Here are some examples - Tracking users login/logout times on your site[^] www.4guysfromrolla/articles/081507-1.aspx[^]

更多推荐

如何显示用户的首次登录时间?

本文发布于:2023-11-06 06:58:30,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1563001.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:首次   时间   用户

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!