Click here to Skip to main content
15,922,584 members
Please Sign up or sign in to vote.
1.50/5 (2 votes)
See more:
my problem is LastLogin and RegisterDate is not store in table User
my database table is [User]
ID               int
Email            primarykey varchar(250)     
Password         varchar(250)
Name             varchar(250)                  
Country          varchar(250)
RegisterDate     datetime                   allownulls 
LastLogin        datetime                   allownulls
Description      varchar(50)
ImageName        varchar(1000)

Login.cs
DataBaseClass dbClass = new DataBaseClass();
    public DataTable dt;
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void OnAuthenticate(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(6);
                Response.Cookies["RFriend_PWD"].Expires = DateTime.Now.AddMonths(6);
                Response.Cookies["RFriend_UID"].Expires = DateTime.Now.AddMonths(6);
            }
            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
        {
            //--------------------------------
            SqlConnection conn = new SqlConnection(@"Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\omar\Documents\Visual Studio 2005\WebSites\WebSite8\App_Data\Database.mdf;Integrated Security=True;User Instance=True");
            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();
                SqlCommand cmd = new SqlCommand("UPDATE [User] SET LastLogon = GETDATE() where id= @UserId", conn);
                SqlParameter param = new SqlParameter();
                param.ParameterName = "@UserId";
                param.Value = Session["UserId"];
                cmd.Parameters.Add(param);
                dbClass.ConnectDataBaseToInser(cmd);//there is problem
            }
            return boolReturnValue;
        }
Posted
Updated 26-Mar-11 22:45pm
v2
Comments
Sandeep Mewara 27-Mar-11 5:42am    
Sure you are beginner and learning. But, are you learning really?
Sergey Alexandrovich Kryukov 27-Mar-11 15:54pm    
Can I up-vote this note? :-)
--SA

1 solution

You should debug and check the command and the parameter values. Also you should provide the type of the parameter (see SqlDbType property).

If the problem happens inside a custom method (ConnectDataBaseToInser) first ensure that you're passing correct information to it and if that's ok then debug inside that method.

A sidenote: also use parameters in your select statement to prevent sql injections etc.
 
Share this answer
 

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