网页文本编辑器提交失败问题

来源:互联网 发布:校园网络建设论文 编辑:程序博客网 时间:2024/05/03 12:05

用的是kindeditor4.17,啰嗦两句,ueditor也不错,可惜官方只注重php方面,.net也支持但是默认的配置图片是不能用的。资料也很少,官方直接没有资料,论坛除php问题外从不解答。虽然很好但我放弃。kindeditor功能还有待加强(图片缩略图、宽高等)


失败的原因是html代码中包含单引号‘,导致与数据库语句的单引号引起意义混乱,
解决办法是把单引号转义为双引号,实际效果不变

实际代码:
protected void Button1_Click(object sender, EventArgs e)
        {
            string constr = "Data Source=127.0.0.1;Database=aaa;User id=sa;PWD=123456;";
            SqlConnection con = new SqlConnection(constr);
            con.Open();
            string xx ="";
            xx=content1.Value.Replace("'","\''").Trim();//把单引号转换为双引号,注意\
            Label1.Text = xx;
            //xx = xx.Replace(" ", "");//去掉空格,不是&nbsp
            string str = "update talk set a ='"+xx+"' where id='27'"; 
            SqlCommand cmd = new SqlCommand(str, con); //创建一个SqlCommand对象,用于执行SQL语句
            cmd.ExecuteNonQuery();
            con.Close();            
        }


原创粉丝点击