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

FCKeditor中的内容如何保存不进数据库呢

2012-01-08 
FCKeditor中的内容怎么保存不进数据库呢?我今天学习了下用FCKeditor,但是想把其中的内容保存到数据库中就

FCKeditor中的内容怎么保存不进数据库呢?
我今天学习了下用FCKeditor,但是想把其中的内容保存到数据库中就是保存不进去,而其他字段的数据则能保存进去。大家帮忙看看是不是我的代码什么地方有问题?


MyFck.aspx

<%@   Register   TagPrefix= "fckeditorv2 "   Namespace= "FredCK.FCKeditorV2 "   Assembly= "FredCK.FCKeditorV2 "   %>
<%@   Page   language= "c# "   Codebehind= "MyFck.aspx.cs "   AutoEventWireup= "false "     validateRequest=false   Inherits= "MyMenu.MyFck "   %>
<!DOCTYPE   HTML   PUBLIC   "-//W3C//DTD   HTML   4.0   Transitional//EN "   >
<HTML>
<HEAD>
<title> AdminFileAdd </title>
<meta   content= "Microsoft   Visual   Studio   .NET   7.1 "   name= "GENERATOR ">
<meta   content= "C# "   name= "CODE_LANGUAGE ">
<meta   content= "JavaScript "   name= "vs_defaultClientScript ">
<meta   content= "http://schemas.microsoft.com/intellisense/ie5 "   name= "vs_targetSchema ">
<LINK   href= "admin.css "   type= "text/css "   rel= "stylesheet ">
</HEAD>
<body   class= "right ">
<form   id= "Form1 "   method= "post "   runat= "server ">
<div> 添加文章 </div>
<div   class= "main ">
<ul>
<li>
标题: <asp:textbox   id= "title "   runat= "server "   Width= "250px "   MaxLength= "50 "> </asp:textbox>
<li>
<FCKEDITORV2:FCKEDITOR   id= "content "   runat= "server "   Width= "90% "   BasePath= "FCKeditor/ "   Height= "350px "> </FCKEDITORV2:FCKEDITOR>
<li>
<asp:button   id= "add "   runat= "server "   Text= "提 交 "> </asp:button> <asp:label   id= "lblErrorShow "   runat= "server "   ForeColor= "Red "> </asp:label> </li> </ul>
</div>
</form>
</body>
</HTML>


MyFck.aspx.cs


using   System;
using   System.Collections;
using   System.ComponentModel;
using   System.Data;
using   System.Drawing;
using   System.Web;
using   System.Web.SessionState;
using   System.Web.UI;
using   System.Web.UI.WebControls;
using   System.Web.UI.HtmlControls;
using   Common;

namespace   MyMenu
{
///   <summary>
///   MyFck   的摘要说明。
///   </summary>
public   class   MyFck   :   System.Web.UI.Page
{
protected   System.Web.UI.WebControls.TextBox   title;
protected   FredCK.FCKeditorV2.FCKeditor   content;
protected   System.Web.UI.WebControls.Label   lblErrorShow;
protected   System.Web.UI.WebControls.Button   add;

private   void   Page_Load(object   sender,   System.EventArgs   e)
{
//   在此处放置用户代码以初始化页面
}

#region   Web   窗体设计器生成的代码
override   protected   void   OnInit(EventArgs   e)
{
//
//   CODEGEN:   该调用是   ASP.NET   Web   窗体设计器所必需的。


//
InitializeComponent();
base.OnInit(e);
}

///   <summary>
///   设计器支持所需的方法   -   不要使用代码编辑器修改
///   此方法的内容。
///   </summary>
private   void   InitializeComponent()
{        
this.add.Click   +=   new   System.EventHandler(this.add_Click);
this.Load   +=   new   System.EventHandler(this.Page_Load);

}
#endregion

private   void   add_Click(object   sender,   System.EventArgs   e)
{
string   sSql;
if(title.Text== " ")
{
lblErrorShow.Text   =   "标题不能为空! ";
return;
}

if(content.Value== " ")
{
lblErrorShow.Text   =   "内容不能为空! ";
return;
}


sSql   =   "Insert   into   news(newstitle,newscontent)   Values( ' "
+title.Text.Trim().ToString()+ " ', ' "+content.Value.Trim()+ " ') ";
AppGlobal.AppDataAccess.ExeSQL(sSql);
}
}
}


[解决办法]
程序出错了吗?

sSql = "Insert into news(newstitle,newscontent) Values( ' "
+title.Text.Trim().ToString()+ " ', ' "+content.Value.Trim()+ " ') ";


如果title.Text、content.Value里面含有单引号的话,sql是不能执行的,
当然也就不能入库!

[解决办法]

试试这个:
string ss=Request.Params[ "content "].ToString();
Response.Write(ss);
Response.End();
测试是否有获取数据
[解决办法]
content.Value应该改为Request[ "content "],因为FCK是在客户端改变的,所以直接content.Value根本取不到值.
[解决办法]
这样子当然不能正常写入啦。。。
sql语句中含有引号,来源于content ,要调用sever.Encode方法,将其编码才能写入
读出的时候再调用server.Decode()方法显示出来
写入前
content=server.Encode(content);
读出后显示之前
content=server.Decode(content);

大小写可能有问题,自己写一下吧

热点排行