I have problem in updating user profile through asp:TextBox. At the time of page load , all the textboxes get loaded with correct values from the database sqlserver.
say First name=SAM {i.e SAM is shown in txtName's textfield) and Last Name=Berton
but when i alter the content of txtName to SAMANTHA and similary for other textboxes, and click on update profile button, Internally txtName.text="SAM" gets retained notwithstanding the changed content of txtName.text="SAMANTHA" by manually altering the content of textbox.So same value that is "SAM" gets stored into the sqlserver rather than "SAMANTHA".
protected void Page_Load(object sender, EventArgs e)
{
loadProfileData();
}
protected void loadProfileData()
{
string connStringProfileload = ConfigurationManager.ConnectionStrings["myconnString"].ConnectionString;
SqlConnection conProfLoad = new SqlConnection(connStringProfileload);
conProfLoad.Open();
string emailAddLogin = User.Identity.Name.ToString();
string strSqlProfileLoad = "SELECT * FROM [gen_profile] WHERE [email]=@email";
SqlCommand cmd = new SqlCommand(strSqlProfileLoad, conProfLoad);
cmd.Parameters.AddWithValue("@email", emailAddLogin);
SqlDataReader drProfileLoad = cmd.ExecuteReader();
while (drProfileLoad.Read())
{
txtName.Text = drProfileLoad["fname"].ToString();
txtLastName.Text=drProfileLoad["lname"].ToString();
}
drProfileLoad.Close();
conProfLoad.Close();
}
protected void BtnUpdtProf_Click(object sender, EventArgs e)
{
string connStringProfileUpdate = ConfigurationManager.ConnectionStrings["myconnString"].ConnectionString;
SqlConnection conUpdateProf = new SqlConnection(connStringProfileUpdate);
conUpdateProf.Open();
string emailAddLogin = User.Identity.Name.ToString();
string strSqlUpdateProf = "UPDATE gen_profile SET fname =@fname, lname =@lname where email=@email;";
SqlCommand cmdUpdate = new SqlCommand(strSqlUpdateProf, conUpdateProf);
cmdUpdate.Parameters.AddWithValue("@fname", txtName.Text.ToUpper().Trim());
cmdUpdate.Parameters.AddWithValue("@lname", txtLastName.Text.ToUpper().Trim());
cmdUpdate.Parameters.AddWithValue("@email", emailAddLogin);
int i = cmdUpdate.ExecuteNonQuery();
conUpdateProf.Close();
if (i == 1)
Response.Redirect("~/prof/resp_update_prof.aspx");
}