update更新数据库,无错误,为什么数据库的值没有变化?

jinlong2015 jinlong2015 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
protected void confirm_Click(object sender, EventArgs e)
{
//获取页面内控件的值
string sno = this.tb_Number.Text;
string sname = this.tb_Name.Text;
string sqq = this.tb_QQ.Text;
this.DropDownList1.ClearSelection();
string sclass = this.DropDownList1.SelectedValue.ToString();
string ssex = this.RadioButtonList1.SelectedValue.ToString();
string stel = this.tb_Tel.Text;
string sadress = this.tb_address.Text;
string semail = this.tb_email.Text;
//建立连接
SqlConnection conn = new SqlConnection(conString);

//command对象
string sql = string.Format("UPDATE Student SET Sname=@sname,Ssex=@ssex,Sqq=@sqq,Stel=@stel,Sclass=@sclass,Sadress=@sadress,Semail=@semail where Sno=@sno");
SqlCommand cmd = new SqlCommand(sql);

cmd.Connection = conn;
cmd.Parameters.AddWithValue("@sno", sno);
cmd.Parameters.AddWithValue("@sname", sname);
cmd.Parameters.AddWithValue("@ssex", ssex);
cmd.Parameters.AddWithValue("@sqq", sqq);
cmd.Parameters.AddWithValue("@stel", stel);
cmd.Parameters.AddWithValue("@sclass", sclass);
cmd.Parameters.AddWithValue("@sadress", sadress);
cmd.Parameters.AddWithValue("@semail", semail);

//执行
try
{
if(conn.State!=ConnectionState.Open)
{
conn.Open();
}

int i = cmd.ExecuteNonQuery();
if (i != 0)
{
Response.Write("<script>alert('更新成功!')</script>");
}
else
{
Response.Write("<script>alert('更新失败!')</script>");
}


}
catch
{
Response.Write("<script>alert('更新过程出现问题!')</script>");
}
finally
{
conn.Close();
}
}
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
jinlong2015
.NET社区 62,274 成员 668,968 内容