asp.net中sql语句中写了update语句 但是执行后数据库数据没有更新,该如何解决
asp.net中sql语句中写了update语句 但是执行后数据库数据没有更新
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection mycon = new SqlConnection("Data source=(local);Initial Catalog=CourseWebsite;Integrated Security=True"))
{
mycon.Open();
string password;
password = TextBox2.Text.Trim();
string mail;
mail = Request["remail"];
SqlCommand cmd = new SqlCommand("update userinfo set password='" + password + "' where mail=@mail", mycon);
cmd.Parameters.Add(new SqlParameter("@mail", mail));
cmd.ExecuteNonQuery();
Response.Redirect("密码修改成功.aspx");
}
}
------解决思路----------------------
没有
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
using (SqlConnection mycon = new SqlConnection("Data source=(local);Initial Catalog=CourseWebsite;Integrated Security=True"))
{
mycon.Open();
string password;
password = TextBox2.Text.Trim();
string mail;
mail = Request["remail"];
SqlCommand cmd = new SqlCommand("update userinfo set password='" + password + "' where mail=@mail", mycon);
cmd.Parameters.Add(new SqlParameter("@mail", mail));
cmd.ExecuteNonQuery();
Response.Redirect("密码修改成功.aspx");
}
}
------解决思路----------------------
没有
protected void Page_Load(object sender, EventArgs e)
{
//在这里面要写个,获取数据.能读取到你要修改的数据
if(!IsPostBack)
{
InitModel(); //这个是获取数据的代码
}
}
public Void InitModel()
{
int id=int.Parse(Request.QueryString["id"]); //这里面的id 是你前台传过的id
//然后给每个控件赋值 把数据库的值取到在控件里面显示
}