大家在修改资料的时候用的 formview还是自己划
如题,为什么我不能更新呢
在修改的from里面
protected void Page_Load(object sender, EventArgs e)
{
string connectionigstring = ConfigurationManager.ConnectionStrings[ "sample2con "].ConnectionString;
SqlConnection con = new SqlConnection(connectionigstring);
SqlCommand cmdFind = new SqlCommand( "select * from Members where UserID= 'a ' ", con);
con.Open();
SqlDataReader sdr = cmdFind.ExecuteReader(CommandBehavior.CloseConnection);
while (sdr.Read())
{
this.lblID.Text = sdr[ "UserID "].ToString();
this.tbUserName.Text = sdr[ "UserName "].ToString();
this.ddlPower.Text = sdr[ "UserPower "].ToString();
this.rbUserSex.Text = sdr[ "UserSex "].ToString();
this.tbYear.Text = (Convert.ToDateTime(sdr[ "UserBirthDay "].ToString())).Year.ToString() ;
this.ddlMonth.Text = (Convert.ToDateTime(sdr[ "UserBirthDay "].ToString())).Month.ToString();
this.ddlDay.Text = (Convert.ToDateTime(sdr[ "UserBirthDay "].ToString())).Day.ToString();
this.tbUserEmail.Text = sdr[ "UserEmail "].ToString();
this.tbUserAddress.Text = sdr[ "UserAddress "].ToString();
}
sdr.Close();
}
protected void btnModify_Click(object sender, EventArgs e)
{
string UserName = this.tbUserName.Text;
string UserSex = this.rbUserSex.Text;
string UserPower = this.ddlPower.Text;
string UserBirthDay;
string UserEmail = this.tbUserEmail.Text;
string UserAddress = this.tbUserAddress.Text;
//这里我输出UserName...值为原来的值,不是新改的值.......
UserBirthDay = tbYear.Text + "- " + ddlMonth.Text + "- " + ddlDay.Text;
string connectionigstring = ConfigurationManager.ConnectionStrings[ "sample2con "].ConnectionString;
SqlConnection con = new SqlConnection(connectionigstring);
SqlCommand cmd = new SqlCommand( "update Members set UserName= ' " + UserName + " ',UserSex= ' " + UserSex + " ',UserEmail= ' " + UserEmail + " ',UserBirthDay= ' " + UserBirthDay + " ',UserAddress= ' " + UserAddress + " ',UserPower= ' " + UserPower + " ',UpdateTime= ' " + DateTime.Now.ToString() + " ' where UserID= ' "+Session[ "UserID "].ToString()+ " ' ", con);
con.Open();
cmd.ExecuteNonQuery();
con.Close();
Response.Write( " <script> location.reload( 'MemberManage.aspx '); </script> ");
//Response.Redirect( "MemberManage.aspx ");
}
[解决办法]
protected void Page_Load(object sender, EventArgs e)
{
if(!this.IsPostBack)
{
xxx
xxx
xxx
}
}