C# 更新配置文件数据无法使用asp.net web表单

C# 更新配置文件数据无法使用asp.net web表单,c#,sql,asp.net,.net,webforms,C#,Sql,Asp.net,.net,Webforms,我试图用web表单更新一个简单的查询,但没有用。我已经试着调试代码,但找不到错误所在。有两种方法page\u load()和editProfile\u click(),其代码如下: protected void Page_Load(object sender, EventArgs e) { int id = Convert.ToInt32(Session["id"]); string connetionString = null;

我试图用web表单更新一个简单的查询,但没有用。我已经试着调试代码,但找不到错误所在。有两种方法
page\u load()
editProfile\u click()
,其代码如下:

    protected void Page_Load(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Session["id"]);
        string connetionString = null;
        SqlConnection con;
        SqlDataReader dr;
        connetionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=AspNetInventory;Integrated Security=True";
        con = new SqlConnection(connetionString);
        try
        {
            con.Open();
            string query = @"SELECT * FROM UserDetails WHERE employeeId = @id";
            SqlCommand cmd = new SqlCommand(query, con);
            cmd.Parameters.AddWithValue("@Id", id);
            dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Username.Text = dr[1].ToString();
                UName.Text = dr[3].ToString();
                UPhoneNo.Text = dr[4].ToString();
                Uemail.Text = dr[5].ToString();
            }
        }//try
        catch (SqlException ex)
        {
            Username.Text = "db Connection fail" + ex;
        }
    }

    protected void SaveProfile_Click(object sender, EventArgs e)
    {
        int id = Convert.ToInt32(Session["id"]);
        string username, fullName, phoneNo, Email;
        username = Convert.ToString(Username.Text);
        fullName = Convert.ToString(UName.Text);
        phoneNo = Convert.ToString(UPhoneNo.Text);
        Email = Convert.ToString(Uemail.Text);

        string connetionString = null;
        SqlConnection con;

        connetionString = @"Data Source=.\SQLEXPRESS;Initial Catalog=AspNetInventory;Integrated Security=True";
        con = new SqlConnection(connetionString);
        try
        {
            con.Open();
            string query = @"UPDATE UserDetails SET userName=@UserName, Name= @fullName, phoneNo = @Phone, Email=@uEmail WHERE employeeId='" + id + "'";
            SqlCommand cmd = new SqlCommand(query, con);

            cmd.Parameters.AddWithValue("@UserName",username);
            cmd.Parameters.AddWithValue("@fullName", fullName);
            cmd.Parameters.AddWithValue("@Phone", phoneNo);
            cmd.Parameters.AddWithValue("@uEmail", Email);
            cmd.ExecuteNonQuery();
            con.Close();
        }//try
        catch (SqlException ex)
        {
            Username.Text = "db Connection fail" + ex;
        }           
    }
当我按下更新配置文件按钮时,数据库中未更改的记录将被提取。请告诉我查询是否有问题

string query = @"UPDATE UserDetails SET userName=@UserName, Name= @fullName, phoneNo = @Phone, Email=@uEmail WHERE employeeId=" + id ;
或:


如果在页面加载下(!IsPostBack){//这是您的代码}请使用,因为当您单击保存按钮时,它首先执行页面加载,然后执行保存单击事件。否则,
page\u load
会覆盖您所做的更改并保存。

您所说的“获取”是什么意思?你的意思是你在屏幕上看不到更改的数据吗?更新数据后是否重新加载数据?你注意到页面加载的时间了吗?你需要控制页面加载代码。如果在IsPostback为true时不排除数据加载,则每次单击需要理解的按钮时都会从数据库中重新加载代码
string query = @"UPDATE UserDetails SET userName=@UserName, Name= @fullName, phoneNo = @Phone, Email=@uEmail WHERE employeeId=@ID";
cmd.Parameters.AddWithValue("@ID", id);