日期:2014-05-18  浏览次数:20617 次

更新数据问题
下面是我的后台代码,我更新的数据含HTML代码,例如:<p>WEB组</p>
<p style=" text-indent:2em; font-size:15px; font-family:'宋体'; line-height:30px; color:#555555;">通过HTML、CSS、C#语言等一系列的学习eb应用系统设计与开发工作,最后的项目开发经验,能独
<p style=" text-indent:2em; font-size:15px; font-family:'宋体'; line-height:30px; color:#555555;">精通SQL语言

C# code

  string content = nei.Text.ToString();
        if (Session["id"] == null)
        {
            Response.Write("<script>alert('请点击编辑,修改后提交!')</script>");
            return;
        }
        int idd=Convert.ToInt32(Session["id"]);
        string sql = "update apply set content='"+content+"' where app_id='"+idd+"'";
        gwolf_bll.action1(sql);
        if (gwolf_bll.action1(sql))
        {
            Response.Write("<script>alert('修改成功!')</script>");
            bind();
            //Response.Redirect(Request.Url.ToString());
        }
        else
        {
            Response.Write("<script>alert('修改失败!')</script>");
        }



------解决方案--------------------
这种会出现特殊字符,最好是用参数化
 string sql = "update apply set content=@content where app_id=@id";
 Cmd.Parameters.Add(new SqlParameter("@id", idd));
 Cmd.Parameters.Add(new SqlParameter("@content",content));
 Cmd.ExecuteNonQuery()