網頁文本編輯器提交失敗問題

用的是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();            
        }


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章