注册日期代码错误 [英] error in register date code

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

问题描述

表名用户

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

代码是

tablename User

ID int
Email varchar(500)
Password varchar(500)
Name varchar(500)
Country varchar(500)
LastLogin datetime
RegisterDate datetime
Description Varchar(500)
ImageName varchar(500)

code is

    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();

        DateTime registerDate = (DateTime)dt.Rows[0]//specified cast is not ["RegisterDate"];valid
        dbClass.ConnectDataBaseToInsert(que);
    }
    return boolReturnValue;
}

推荐答案

用于DateTime验证.
For DateTime validation..try this
DateTime temp;
if(DateTime.TryParse(dt.Rows[0].ItemArray[6].toString(), out temp))
{
//Valid date
}
else
{
//Invalid date
}


通过查看您的代码,看来您犯了一个令人盲目的错误.首先,您使用dt.Rows[0]设置Session["UserId"],然后尝试再次使用它来设置registerDate.您确定不是将日期时间用作用户ID吗?如果是的话,您是否不愿意尝试检查dt.Rows[0]是什么类型?也许这是一个字符串,您需要使用DateTime.Parse().
From looking at your code it seems like you''ve made a blinding mistake. First you use dt.Rows[0] to set the Session["UserId"] and then you try and use it again to set registerDate. Surely you''re not using a date time as the user''s Id? And if you are, have you bothered trying to check what type dt.Rows[0] is? Perhaps it''s a string and you need to use DateTime.Parse().


更改此内容:

Change this:

DateTime registerDate = (DateTime)dt.Rows[0]//specified cast is not ["RegisterDate"];valid



为此:



To this:

DateTime registerDate = (DateTime)dt.Rows[0]["RegisterDate"];



您的"dt.Rows [0]"是错误的.首先给出行索引,然后给出列索引.



Your "dt.Rows[0]" is wrong. First give row index, then column index.


这篇关于注册日期代码错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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