public partial class mypost_modify : System.Web.UI.Page
{string poid = "";//统一定义poid
protected void Page_Load(object sender, EventArgs e)
{
if (Request.QueryString["poid"] == null) Response.Redirect("./sign_in.aspx");//poid为空,返回登录页面
poid = Request.QueryString["poid"].ToString();
try
{
string sql = "select * from post_table where post_id='" + poid.ToString() + "'";
DataAccess da = new DataAccess();
DataSet ds = da.dataSet(sql);
if (ds != null && ds.Tables[0] != null && ds.Tables[0].Rows.Count > 0)
{
TextBox1.Text = ds.Tables[0].Rows[0]["post_title"].ToString().Trim();
TextBox2.Text = ds.Tables[0].Rows[0]["post_details"].ToString().Trim();
}
}
catch (Exception ex) { }
finally { }
}
protected void Button1_Click(object sender, EventArgs e)
{
string sql = "update post_table set post_title='" + TextBox1.Text + "' , post_details='";
sql = sql + TextBox2.Text + "' where post_id='" + poid.ToString() + "'";
try
{
DataAccess da = new DataAccess();
da.ExecuteSql(sql);
Label1.Text = "修改成功";
}
catch (Exception ex) { Label1.Text = "修改失败"; }
}
}
更新无反应,调试发现标题所述错误,
System.NullReferenceException HResult=0x80004003 Message=未将对象引用设置到对象的实例。 Source=<无法计算异常源> StackTrace: <无法计算异常堆栈跟踪>
不知道哪里错了000
if (Request.QueryString["poid"] == null)
{
Response.Redirect("./sign_in.aspx");//poid为空,返回登录页面
Response.End();//最好加上这句停止后续代码执行,Response.Redirect好像和framework版本有关,有些会停止后续代码执行,有些不会。
}