this code will tell me that my update was successful but will not update my database. I have stripped the code down to nothing and still cannot find the problem.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;
namespace GigGuide
{
publicpartialclass userProfile : System.Web.UI.Page
{
protectedvoid Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
LblUserName.Text = Convert.ToString(Session["New"]);
string fillTextBoxes = "Select FirstName, Surname,TelephoneNo,PersonalEmail,Password,ContactbyText,ContactByEmail from Personal where UserName ='" + LblUserName.Text + "'";
SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectDatabaseConnectionString"].ConnectionString);
SqlCommand com = new SqlCommand(fillTextBoxes, conn);
SqlDataReader reader;
try
{
conn.Open();
reader = com.ExecuteReader();
reader.Read();
TextBoxFirstName.Text = reader["FirstName"].ToString();
TextBoxSurName.Text = reader["Surname"].ToString();
TextBoxTelNo.Text = reader["TelephoneNo"].ToString();
TextBoxOldemail.Text = reader["PersonalEmail"].ToString();
TextBoxOldPassword.Text = reader["Password"].ToString();
reader.Close();
conn.Close();
}
catch (Exception ex)
{
Response.Write("ERROR" + ex.ToString());
}
}
}
protectedvoid ButtonUpdate_Click(object sender, EventArgs e)
{
try
{
SqlConnection conn1 = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectDatabaseConnectionString"].ConnectionString);
conn1.Open();
// conn1.Open();
SqlCommand com1;
string updateQuery = "update Personal set PersonalEmail = @email,FirstName = @fname, Surname = @sname,TelephoneNo = @telno, Password = @password, ContactbyText = @conText, ContactByEmail = @conEmail Where UserName = '" + LblUserName + "'";
com1 = new SqlCommand(updateQuery, conn1);
com1.Parameters.AddWithValue("@email", TextBoxNewEmail.Text);
com1.Parameters.AddWithValue("@password", TextBoxNewPassword.Text);
com1.Parameters.AddWithValue("@fname", TextBoxFirstName.Text);
com1.Parameters.AddWithValue("@sname", TextBoxSurName.Text);
com1.Parameters.AddWithValue("@telno", TextBoxTelNo.Text);
// com1.Parameters.AddWithValue("@location", locID);
com1.Parameters.AddWithValue("@conText", RadioButtonListText.SelectedValue);
com1.Parameters.AddWithValue("@conEmail", RadioButtonListEmail.SelectedValue);
com1.ExecuteNonQuery();
conn1.Close();
Response.Write("Update was successful");
}
catch (Exception ex)
{
Response.Write("error" + ex.ToString());
}
}
}
}