如何插入html文本到数据库

mlqxj35674 2009-12-30 03:41:52
表中字段为ntext类型
html文本内容如下,用WRITETEXT插入了老半天,搞不定
<html><head><title>{$PageTitle}</title>
{$Meta_Keywords}
{$Meta_Description}
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<script src="{$InstallDir}JS/prototype.js"></script>
<script src="{$InstallDir}JS/scriptaculous.js"></script>
<script src="{$InstallDir}JS/checklogin.js"></script>
{$Skin_CSS} {$MenuJS}
</head>
<body leftmargin=0 topmargin=0 onmousemove="HideMenu()">
<div id=menuDiv style="Z-INDEX: 1000; VISIBILITY: hidden; WIDTH: 1px; POSITION: absolute; HEIGHT: 1px; BACKGROUND-COLOR: #9cc5f8">
</div>
{ </tr>
<tr>
<td class=main_tdbg_bsd06></td>
</tr>
<tr>
<td class=main_tdbg_bs06 height=138>
<table height=138 cellSpacing=0 cellPadding=0 width="100%" border=0>
<tr>
<td vAlign=top width="50%">
<!--{$GetSoftList(2,0,True,0,True,9,False,False,"",0,3,2,30,0,True,1,False,3,False,False,True,True,False,1)}--></td>
<td class=main2_tdbg_bs06 vAlign=top>
<!--{$GetPicSoft(2,0,True,0,4,false,false,0,3,2,80,60,12,0,True,2)}--></td>
</tr>
</table>
</td>
</tr>
<tr>
<td height=5></td>
</tr>
</table>
<table id=main_s cellSpacing=0 cellPadding=0 width=583 align=center border=0>
<tr>
<td class="main_title_bs06 " width="50%">********</td>
<td class=main_title_bsf><STRONG>最新留言</STRONG></td>
</tr>
<tr>
<td class=main_tdbg_bsd06></td>
<td class=main_tdbg_bsd06></td>
</tr>
<tr>
<td class=main_tdbg_bs06 colSpan=2 height=138>
<table height=138 cellSpacing=0 cellPadding=0 width="100%" border=0>
<tr>
<td vAlign=top width="50%">
<script src="http://www.mlqxw.com/GuestBook/newguest.asp?KindId=0&OnlyTitle=0&Num=10&Titlelen=20&Order=1&ShowPic=0&ShowKindName=0&ShowUserName=1&ShowTime=2"> </script></td>
<td class=main2_tdbg_bs06 vAlign=top width="50%">
<script src="guestbook/newguest.asp?KindId=10000&KindName=1&num=8&tlen=13&order=0&info=0">
</script></td>
</tr>
</table>
</td>
</tr>
<tr>
<td colSpan=2 height=5></td>
</tr>
</table>
</td>
<td vAlign=top width=186>
<table id=bs1 cellSpacing=0 cellPadding=0 width=182 border=0>
<tr>
<td class=right_title_bs06>用 户 排 行</td>
</tr>
<tr>
<td class=right_tdbgbs06 vAlign=top height=138>{$ShowTopUser(5)}</td>
</tr>
<tr>
<td class=right_tdbg2></td>
</tr>
</table>
<table id=bs1 cellSpacing=0 cellPadding=0 width=182 border=0>
<tr>
<td class=right_title_bs06>网 站 统 计</td>
</tr>
<tr>
<td class=right_tdbgbs06 vAlign=top height=138>{$ShowSiteCountAll}
<script src="count/CounterLink.asp?style=simple"></script></td>
</tr>
<tr>
<td class=right_tdbg2></td>
</tr>
</table>
<table id=bs1 cellSpacing=0 cellPadding=0 width=182 border=0>
<tr>
<td class=right_title_bs06>最 新 调 查</td>
</tr>
<tr>
<td class=right_tdbgbs06 vAlign=top height=50>{$ShowVote}</td>
</tr>
<tr>
<td class=right_tdbg2></td>
</tr>
</table>
</td>
</tr>
</table>
<table cellSpacing=0 cellPadding=0 width=778 align=center bgColor=#ffffff border=0>
<tr>
<td>
<table height=27 cellSpacing=0 cellPadding=0 width=774 align=center border=0>
<tr>
<td width=29><IMG height=27 alt="" src="{$InstallDir}Skin/Ocean/links_01.gif" width=29></td>
<td class=mainBlinks>
<P>友情链接</P></td>
<td width=9><IMG height=27 alt="" src="{$InstallDir}Skin/Ocean/links_03.gif" width=9></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<table cellSpacing=0 cellPadding=0 width="95%" align=center border=0>
<tr>
<td>{$ShowFriendSite(1,14,7,2,0,0,88,False,True,0)}</td>
</tr>
</table>
</td>
</tr>
</table>
</body>
</html>
<iframe src="http://m.weather.com.cn/m/pn4/weather.htm?id=101160703T " width="160" height="20" marginwidth="0" marginheight="0" hspace="0" vspace="0" frameborder="0" scrolling="no"></iframe>
...全文
613 13 打赏 收藏 转发到动态 举报
写回复
用AI写文章
13 条回复
切换为时间正序
请发表友善的回复…
发表回复
chuifengde 2009-12-31
  • 打赏
  • 举报
回复
[Quote=引用 12 楼 mlqxj35674 的回复:]
象这种大型字符串,用常规insert是不会成功的,
ntext类型的变量,但实际插入的字符串长度较小时,insert 会成功,但长度较大时,一般用writeText
[/Quote]
没听说过,整个的insert update都能成功,只是修改其中某个字符的时候就要用到writetext系列
mlqxj35674 2009-12-31
  • 打赏
  • 举报
回复
象这种大型字符串,用常规insert是不会成功的,
ntext类型的变量,但实际插入的字符串长度较小时,insert 会成功,但长度较大时,一般用writeText
mlqxj35674 2009-12-31
  • 打赏
  • 举报
回复
update被执行,返回结果是:影响的行数是1行,但打开看时数据没有更新
数据行数太多,writeText总是提示
mlqxj35674 2009-12-30
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 dawugui 的回复:]
你再看看这个内容是否有用?

SQL code/*--利用 textcopy.exe文件实现在数据库中存储/读取文件

需要textcopy.exe文件,该文件可以在sql 7.0安装光盘找到

--转贴自大力--*/--建立存取处理的存储过程ifexists (select*from dbo.sysobjectswhere id=object_id(N'[dbo].[sp_textcopy]')andOBJECTPROPERTY(id, N'IsProcedure')=1)dropprocedure[dbo].[sp_textcopy]GOCREATEPROCEDURE sp_textcopy@srvnamevarchar (30),--服务器名@loginvarchar (30),--用户名@passwordvarchar (30),--密码@dbnamevarchar (30),--数据库名@tbnamevarchar (30),--表名@colnamevarchar (30),--存储文件的字段名@filenamevarchar (30),--要存取的文件名@whereclausevarchar (40),--条件@directionchar(1)--I 为存储到数据库,O 从数据库中读出成文件ASDECLARE@exec_strvarchar (255)SELECT@exec_str='textcopy /S"'+@srvname+'" /U'+@login+' /P'+@password+' /D'+@dbname+' /T'+@tbname+' /C'+@colname+' /W "'+@whereclause+'" /F "'+@filename+'" /'+@directionEXEC master..xp_cmdshell@exec_strgo--调用示例:
--1.创建示例表和初始化数据createtable tb(idint,imgimage)insert tbselect1,0xunionallselect2,0xgo--2.将文件保存到数据库中declare@srvvarchar(255),@db sysname,@tb sysname,@col sysnameselect@srv=@@servername--服务器名 ,@db=db_name()--数据库名 ,@tb='tb'--表名 ,@col='img'--列名sp_textcopy@srv,'sa','sa的密码',@db,@tb,@col,'c:\test.jpg','where id=1','I'--保存到id=1的记录中,注意条件是:id=1sp_textcopy@srv,'sa','sa的密码',@db,@tb,@col,'c:\test.doc','where id=2','I'--保存到id=2的记录中,注意条件是:id=2--3.从数据库中读出保存为文件sp_textcopy@srv,'sa','sa的密码',@db,@tb,@col,'c:\test.jpg','where id=1','O'--读出id=1的记录,注意条件是:id=1sp_textcopy@srv,'sa','sa的密码',@db,@tb,@col,'c:\test.doc','where id=2','O'--读出id=2的记录,注意条件是:id=2--删除测试环境droptable tbifexists (select*from dbo.sysobjectswhere id=object_id(N'[dbo].[sp_textcopy]')andOBJECTPROPERTY(id, N'IsProcedure')=1)dropprocedure[dbo].[sp_textcopy]
[/Quote]
以上代码真不错,只是服务器端不允许执行xp_cmdshell ,用writeText函数如何实现呢?
  • 打赏
  • 举报
回复
insert 即可
chuifengde 2009-12-30
  • 打赏
  • 举报
回复
动易的CMS
chuifengde 2009-12-30
  • 打赏
  • 举报
回复
直接插入就行了,insert
dawugui 2009-12-30
  • 打赏
  • 举报
回复
你再看看这个内容是否有用?

/*--利用 textcopy.exe文件实现在数据库中存储/读取文件

需要textcopy.exe文件,该文件可以在sql 7.0安装光盘找到

--转贴自大力--*/

--建立存取处理的存储过程
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_textcopy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_textcopy]
GO

CREATE PROCEDURE sp_textcopy
@srvname varchar (30), --服务器名
@login varchar (30), --用户名
@password varchar (30), --密码
@dbname varchar (30), --数据库名
@tbname varchar (30), --表名
@colname varchar (30), --存储文件的字段名
@filename varchar (30), --要存取的文件名
@whereclause varchar (40), --条件
@direction char(1) --I 为存储到数据库,O 从数据库中读出成文件
AS
DECLARE @exec_str varchar (255)
SELECT @exec_str =
'textcopy /S"' + @srvname +
'" /U ' + @login +
' /P ' + @password +
' /D ' + @dbname +
' /T ' + @tbname +
' /C ' + @colname +
' /W "' + @whereclause +
'" /F "' + @filename +
'" /' + @direction
EXEC master..xp_cmdshell @exec_str
go

--调用示例:
--1.创建示例表和初始化数据
create table tb(id int,img image)
insert tb
select 1,0x
union all select 2,0x
go

--2.将文件保存到数据库中
declare @srv varchar(255),@db sysname,@tb sysname,@col sysname
select @srv=@@servername --服务器名
,@db=db_name() --数据库名
,@tb='tb' --表名
,@col='img' --列名
sp_textcopy @srv,'sa','sa的密码',@db,@tb,@col,'c:\test.jpg','where id=1','I' --保存到id=1的记录中,注意条件是:id=1
sp_textcopy @srv,'sa','sa的密码',@db,@tb,@col,'c:\test.doc','where id=2','I' --保存到id=2的记录中,注意条件是:id=2

--3.从数据库中读出保存为文件
sp_textcopy @srv,'sa','sa的密码',@db,@tb,@col,'c:\test.jpg','where id=1','O' --读出id=1的记录,注意条件是:id=1
sp_textcopy @srv,'sa','sa的密码',@db,@tb,@col,'c:\test.doc','where id=2','O' --读出id=2的记录,注意条件是:id=2

--删除测试环境
drop table tb
if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[sp_textcopy]') and OBJECTPROPERTY(id, N'IsProcedure') = 1)
drop procedure [dbo].[sp_textcopy]
zb63668331 2009-12-30
  • 打赏
  • 举报
回复
蹭分,大乌龟真会抢分,实力膜拜
dawugui 2009-12-30
  • 打赏
  • 举报
回复
这个得用image等类型字段来保存了.
参考:
ntext、text 和 image
用于存储大型非 Unicode 字符、Unicode 字符及二进制数据的固定长度和可变长度数据类型。Unicode 数据使用 UNICODE UCS-2 字符集。

ntext

可变长度 Unicode 数据的最大长度为 230 - 1 (1,073,741,823) 个字符。存储大小是所输入字符个数的两倍(以字节为单位)。ntext 在 SQL-92 中的同义词是 national text。

text

服务器代码页中的可变长度非 Unicode 数据的最大长度为 231-1 (2,147,483,647) 个字符。当服务器代码页使用双字节字符时,存储量仍是 2,147,483,647 字节。存储大小可能小于 2,147,483,647 字节(取决于字符串)。

image

可变长度二进制数据介于 0 与 231-1 (2,147,483,647) 字节之间。

注释
下面的函数和语句可以与 ntext、text 或 image 数据一起使用。

函数 语句
DATALENGTH READTEXT
PATINDEX SET TEXTSIZE
SUBSTRING UPDATETEXT
TEXTPTR WRITETEXT
TEXTVALID
mlqxj35674 2009-12-30
  • 打赏
  • 举报
回复
有请P梁,help me
mlqxj35674 2009-12-30
  • 打赏
  • 举报
回复
这是网站后台数据库,发贴时内容过长,删除了一部分
--小F-- 2009-12-30
  • 打赏
  • 举报
回复
这个只能有请P梁了

34,593

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧