“上次登录”存储过程出现问题

时间:2012-11-15 15:48:15

标签: asp.net visual-studio-2010 sql-server-2008

向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!";
        }
    }
}

0 个答案:

没有答案