Michelle Carthy

Michelle Carthy

  • NA
  • 52
  • 11.5k

How to update user details using sessions

Jan 30 2018 4:14 PM
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
 
   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");
}
 

Answers (2)