请问asp.net我想根据上一个页面传的id修改数据库对应id的信息。为什么显示修改成功数据库却没有任何变化 20
protectedvoidButton1_Click(objectsender,EventArgse){if(TextBox1.Text==""||TextBox2.Te...
protected void Button1_Click(object sender, EventArgs e)
{
if (TextBox1.Text == "" || TextBox2.Text == "")
{
Response.Write(@"<script>alert('输入内容不允许为空');</script>");
}
else
{
SqlConnection conn = null;
try
{
string connStr = @"Data Source=.;Initial Catalog=LJXYbus;Integrated Security=True;";
conn = new SqlConnection(connStr);
conn.Open();
string sql = "update BUS set Time='" + TextBox1.Text.ToString() + "',Route='" + TextBox2.Text.ToString() + "' where ID='" + Request.QueryString["id"] + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
Response.Write("<script>alert('修改成功!');window.location.href ='BUS.aspx'</script>");
}
catch
{
Response.Write("<script>alert('修改失败,请稍后再试!');window.location.href ='BUS.aspx'</script>");
}
finally
{
if (null != conn)
{
conn.Close();
}
}
} 展开
{
if (TextBox1.Text == "" || TextBox2.Text == "")
{
Response.Write(@"<script>alert('输入内容不允许为空');</script>");
}
else
{
SqlConnection conn = null;
try
{
string connStr = @"Data Source=.;Initial Catalog=LJXYbus;Integrated Security=True;";
conn = new SqlConnection(connStr);
conn.Open();
string sql = "update BUS set Time='" + TextBox1.Text.ToString() + "',Route='" + TextBox2.Text.ToString() + "' where ID='" + Request.QueryString["id"] + "'";
SqlCommand cmd = new SqlCommand(sql, conn);
SqlDataReader reader = cmd.ExecuteReader();
Response.Write("<script>alert('修改成功!');window.location.href ='BUS.aspx'</script>");
}
catch
{
Response.Write("<script>alert('修改失败,请稍后再试!');window.location.href ='BUS.aspx'</script>");
}
finally
{
if (null != conn)
{
conn.Close();
}
}
} 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询