如何更新使用会话C#ASP.NET登录的用户的详细信息 [英] How do I update details of the user that is logged in using sessions C# ASP.NET

查看:59
本文介绍了如何更新使用会话C#ASP.NET登录的用户的详细信息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我希望能够更新登录用户的详细信息。所以我想要更新多个属性但是我希望用户每次想要更改时都不必输入他们的ID一些东西。这是我在保存按钮下的代码,但除了重定向到另一页外没有任何反应。任何帮助将不胜感激



我尝试过:



So I want to be able to update the details of the user that is logged in. So I have multiple attributes that I would like to update however I want the user not have to enter their ID each time they would like to change something. This is my code under the save button however nothing happens except redirect to the other page. Any help would be kindly appreciated

What I have tried:

<pre> protected void btnTenantSave_Click(object sender, EventArgs e)
    {
        if (!Page.IsPostBack)
        {
            //Creating a connection to my database using the connection string
            string cs = System.Configuration.ConfigurationManager.ConnectionStrings["rent-dbConnectionString1"].ConnectionString;
        SqlConnection con = new SqlConnection(cs);
        //preparing a query which will update the data in the database with the data entered into the textboxes
        SqlCommand cmd = new SqlCommand("UPDATE Tenants SET Tenant_FullName='" + this.txtTenantFullName.Text + "',Tenant_Email='" + this.txtTenantEmail.Text + "',Tenant_TelNum='" + this.txtTenantTelNum.Text + "',Tenant_EmName= '" + this.txtTenantEmName.Text + "',Tenant_EmNum= '" + this.txtTenantEmNum.Text + "',Tenant_WorkStatus= '" + this.txtWorkstatus.Text + "'Where Tenant_Email='" + Session["TenantLogin"] + "';", con);
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
        }
        Response.Redirect("TenantIndex.aspx");
       
    }

推荐答案

当用户登录时,你需要将他们的id存储在Session变量中然后您可以随时使用它。
When the user logs in you need to store their id in a Session variable and then you can use that anytime you need it.


这篇关于如何更新使用会话C#ASP.NET登录的用户的详细信息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆