Click here to Skip to main content
15,030,320 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
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;
        }
    }


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.



[edit]Database table and error message from OP - OriginalGriff[/edit]
Posted
Updated 13-Apr-11 21:50pm
v3
Comments
JF2015 14-Apr-11 3:32am
   
Edited to add pre tags.
Tarun.K.S 14-Apr-11 3:33am
   
Could you please elaborate where is the error coming?
[no name] 14-Apr-11 4:33am
   
string updateLastLogin = "Update [User] SET LastLogin='" + System.DateTime.Now.ToString() + "' where Id='" + Session["UserId"].ToString() + "'";
m@dhu 14-Apr-11 3:33am
   
error in code
where? what is the error?
[no name] 14-Apr-11 4:31am
   
string updateLastLogin = "Update [User] SET LastLogin='" + System.DateTime.Now.ToString() + "' where Id='" + Session["UserId"].ToString() + "'";
jim lahey 14-Apr-11 3:34am
   
So, error in code.. what kind of error? on which line?
lw@zi 14-Apr-11 3:34am
   
You have asked 30 questions so far and you are still using text speak. You must have been told before and I am telling again: Please do not use text speak.

Please post only the relevant code and the mention the error you are getting and in which line. Also tell us what have you tried so far.
lw@zi 14-Apr-11 3:40am
   
Do not repost. Update this question using Improve Question link and delete your repost.
Sandeep Mewara 14-Apr-11 3:50am
   
Care to elaborate what exactly!!!
OriginalGriff 14-Apr-11 3:51am
   
I have moved the database table and error message from your other copy of this question to here, and deleted the other question.
In future, please use the "Improve Question" widget instead of creating a new question.

1 solution

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?.
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900