如何获得用户的注册日期 [英] How to get the user's registration date

查看:89
本文介绍了如何获得用户的注册日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请告诉我如何获得用户在网站上注册的日期


ID int
电子邮件varchar(500)
密码varchar(500)
名称varchar(500)
国家varchar(500)
LastLogin日期时间
RegisterDate日期时间//如何注册日期
说明Varchar(500)
ImageName varchar(500)

login.cs


please tell me how i get the date user register in website


ID int
Email varchar(500)
Password varchar(500)
Name varchar(500)
Country varchar(500)
LastLogin datetime
RegisterDate datetime//how to register date
Description Varchar(500)
ImageName varchar(500)

login.cs


SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\Project1\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
string chkUser = "Select * FROM [User] where Email='" + UserName + "' AND Password='" + Password + "'";
dt = dbClass.ConnectDataBaseReturnDT(chkUser);
if (dt.Rows.Count > 0)
{
  boolReturnValue = true;
  Session["UserId"] = dt.Rows[0]["Id"].ToString();
  string que = "UPDATE [User] SET LastLogin = GETDATE() where Id=" + Session["UserId"].ToString();// here is code of  lastlogin
<pre lang="midl">string que1= DateTime.Parse(dt.Rows[0]["RegisterDate"].ToString());
               dbClass.ConnectDataBaseToInsert(que);

//无法将隐式类型system.date.time转换为字符串

dbClass.ConnectDataBaseToInsert(que1);
}
return boolReturnValue;

我想在用户注册时如何获取注册日期

//can not convert implicit type system.date.time to string

dbClass.ConnectDataBaseToInsert(que1);
}
return boolReturnValue;

i want how i get the register date when user register

推荐答案

在注册过程中创建用户时,请保存当前日期.
当您在上面的代码中读回信息时,只需读出值即可:
When you create the user as part of the registration process, save the current date.
When you read the info back in your code above, just read out the value:
DateTime registeredOn = (DateTime) dt.Rows[0]["RegisterDate"];



尽管我建议您想寻找一种更好的方法来处理数据库访问:串联字符串非常危险:它可能导致意外或故意的SQL注入攻击.看看使用参数化查询,而不是SqlCommand.Parameters.AddWithValue方法



Though I would suggest you want to look at a better way to handle your database access: concatenating strings is very dangerous: It can lead to accidental or deliberate SQL Injection attacks. Look at using Parametrized queries instead, using the SqlCommand.Parameters.AddWithValue method


您可以尝试这样
You can try like this
DateTime.Parse( dt.Rows[0]["RegisterDate"].ToString());


或像这样


or like this

Convert.ToDatetime(dt.Rows[0]["RegisterDate"].ToString())


这篇关于如何获得用户的注册日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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