0

ユーザー テーブルに「LastLogin」列を追加しましたが、ユーザーがパスワードで保護されたページに初めてログインしたときの最終ログイン日のみが保存されます。

同じユーザーが 2 回目にログインすると、セルには最後のログインが反映されません。これが私のストアドプロシージャです:

これが私のストアドプロシージャです:

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