为什么我的数据不能更新
代码如下:
protected void Page_Load(object sender, EventArgs e)
{
//*****************ceshi*********
Session.Add( "Name ", "张海波 ");
Session.Add( "Pwd ", "123 ");
//*****************ceshi**********
if (!IsPostBack) {
Page.Title = Session[ "Name "].ToString() + "的个人信息 ";
SqlDatabase db = new SqlDatabase();
db.DbConn.Open();
db.DbCmd.CommandText = "select* from Userinfo where Uname= ' " + Session[ "Name "] + " ' ";
SqlDataReader dr = db.DbCmd.ExecuteReader();
if (dr.Read())
{
lbName.Text = dr[1].ToString();
txtEmail.Text =dr[4].ToString ();
txtInfo.Text =dr[5].ToString ();
}
db.DbConn.Close();
}
}
protected void btnEdit_Click(object sender, EventArgs e)
{
SqlDatabase db = new SqlDatabase();
db.DbConn.Open();
db.DbCmd.CommandType = CommandType.StoredProcedure;
db.DbCmd.CommandText = "UpDateUser ";
db.DbCmd.Parameters.AddWithValue( "@UName ",Session [ "name "]);
db.DbCmd.Parameters.AddWithValue( "@UPwd ",txtNewPwd.Text.Trim ());
db.DbCmd.Parameters.AddWithValue( "@UEmail ",txtEmail.Text);
db.DbCmd.Parameters.AddWithValue( "@UInfo ",txtInfo.Text);
db.DbCmd.ExecuteNonQuery();
db.DbConn.Close();
}
在页面加载的时候读取数据并填充到相应的控件上显示,然后修改控件中的值进行更新