首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

更新数据有关问题

2012-04-23 
更新数据问题下面是我的后台代码,我更新的数据含HTML代码,例如:pWEB组/pp style text-indent:2em

更新数据问题
下面是我的后台代码,我更新的数据含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()

热点排行