请检查代码. [英] plz check the code..

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

问题描述

代码错误
login.cs

error in code
login.cs

DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void ctlLogin_Authenticate(object sender, AuthenticateEventArgs e)
    {
        bool Authenticated = false;
        CheckBox chBox = (CheckBox)ctlLogin.FindControl("RememberMe");
        Authenticated = UserAuthenticate(ctlLogin.UserName, ctlLogin.Password);
        e.Authenticated = Authenticated;
        if (Authenticated == true)
        {
            if (chBox.Checked == true)
            {
                Response.Cookies["RFriend_Email"].Value = ctlLogin.UserName;
                Response.Cookies["RFriend_PWD"].Value = ctlLogin.Password;
                Response.Cookies["RFriend_UID"].Value = Session["UserId"].ToString();
                Response.Cookies["RFriend_Email"].Expires = DateTime.Now.AddMonths(3);
                Response.Cookies["RFriend_PWD"].Expires = DateTime.Now.AddMonths(3);
                Response.Cookies["RFriend_UID"].Expires = DateTime.Now.AddMonths(3);
            }
            Response.Redirect("UserDetails.aspx?Id=" + Session["UserId"].ToString());
        }
    }
    private bool UserAuthenticate(string UserName, string Password)
    {
        bool boolReturnValue = false;
        //--------------------------------
        //Check UserID From Config File
        if (UserName == "Rahul" && Password == "Saxena")
        {
            boolReturnValue = true;
            return boolReturnValue;
        }
        else
        {
            //--------------------------------
            dt = new DataTable();
            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 updateLastLogin = "Update [User] SET LastLogin=''" + System.DateTime.Now.ToString() + "'' where Id=''" + Session["UserId"].ToString() + "''";
                dbClass.ConnectDataBaseToInsert(updateLastLogin);
            }
            return boolReturnValue;
        }
    }



在OP中添加了同一问题的其他帖子(已删除)

数据库表用户是



Added from the OP other post of the same question (deleted)

database table user is

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


错误是


error is

The conversion of a char data type to a datetime data type resulted in an out-of-range datetime value.
The statement has been terminated.




来自OP的数据库表和错误消息-OriginalGriff [/edit]




[edit]Database table and error message from OP - OriginalGriff[/edit]

推荐答案

string updateLastLogin ="Update [User] SET LastLogin =""+ System.DateTime.Now.ToString()+''其中Id =''" + Session ["UserId"].ToString()+''";

为什么要将DateTime转换为字符串. LastLogin是DateTime数据类型,您正在为其输入字符串值.

还有,为什么不使用参数化查询呢?
string updateLastLogin = "Update [User] SET LastLogin=''" + System.DateTime.Now.ToString() + "'' where Id=''" + Session["UserId"].ToString() + "''";

why are you converting the DateTime to string. LastLogin is the DateTime datatype and you are inputting the string value to it.

And why don''t you use a parameterized query?.


这篇关于请检查代码.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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