0

在 User 表中添加了“LastLogin”列,但是,它仅存储用户第一次登录受密码保护的页面时的最后登录日期。

当同一用户第二次登录时,单元格不会反映他的最后一次登录。这是我的存储过程:

这是我的存储过程:

ALTER PROCEDURE [dbo].[UpdateLastLogin] (
@intUserID int
)
    -- Add the parameters for the stored procedure here
AS

SET NOCOUNT ON

UPDATE Users SET LastLogin = GETDATE() WHERE UserID = @intUserID

这是我的代码:

public partial class Login : System.Web.UI.Page
{


    protected void Page_Load(object sender, EventArgs e)
     {
        //SqlConnection oConnection = new SqlConnection(ConfigurationManager.ConnectionStrings["XXXConnectionString"].ConnectionString);
        //SqlCommand oCommand = new SqlCommand();
        //oCommand.Connection = oConnection;
        //oCommand.CommandText = "UpdateLastLogin";
        //oCommand.CommandType = CommandType.StoredProcedure;
        //oCommand.Parameters.Add(new SqlParameter("@intUserID", SqlDbType.NVarChar, 10)).Value = Int32.MaxValue;
        //SqlDataAdapter adpt = new SqlDataAdapter(oCommand);
        //DataSet ds = new DataSet();
        //adpt.Fill(ds);
    }
    protected void loginButton_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["3GPSConnectionString"].ConnectionString);
        con.Open();
        string cmdStr = "Select count(*) from Users where UserName='" + userTextBox.Text + "'";
        SqlCommand Checkuser = new SqlCommand(cmdStr, con);
        int temp = Convert.ToInt32(Checkuser.ExecuteScalar().ToString());
        if (temp == 1)
        {
            string cmdStr2 = "Select Password from Users where UserName='" + userTextBox.Text + "'";
            SqlCommand pass = new SqlCommand(cmdStr2, con);
            string password = pass.ExecuteScalar().ToString();
            con.Close();

            if (password == pwdTextBox.Text)
            {
                Session["New"] = userTextBox.Text;
                Response.Redirect("/Protected/Default.aspx");
            }
            else
            {
                userCompareLbl.Visible = true;
                userCompareLbl.Text = "Invalid Password!";
            }
        }
        else
        {
            userCompareLbl.Visible = true;
            userCompareLbl.Text = "Invalid Username!";
        }
    }
}
4

0 回答 0