如何用存储过程保存和读取ntext,image字段??

sunon 2003-08-30 09:41:02
如何用存储过程保存和读取ntext,image字段??

我用ASP调用存储过程的.

.Parameters.append .CreateParameter("@Content",?,adParamInput,?,Content)

“?”处应写什么?

多谢!!
...全文
122 12 打赏 收藏 转发到动态 举报
写回复
用AI写文章
12 条回复
切换为时间正序
请发表友善的回复…
发表回复
aierong 2003-10-26
  • 打赏
  • 举报
回复
---涛声依旧--- 2003-10-26
  • 打赏
  • 举报
回复
up
wzhgsww 2003-10-26
  • 打赏
  • 举报
回复
up
zjcxc 元老 2003-10-07
  • 打赏
  • 举报
回复
.CmdText="存储过程名"
.Parameters.refresh
.Parameters("@Content")=Content
pengdali 2003-10-07
  • 打赏
  • 举报
回复
Private Sub Class_Terminate
form.RemoveAll
file.RemoveAll
set form=nothing
set file=nothing
upfile_5xSoft_Stream.close
set upfile_5xSoft_Stream=nothing
End Sub


Private function GetFilePath(FullPath)
If FullPath <> "" Then
GetFilePath = left(FullPath,InStrRev(FullPath, "\"))
Else
GetFilePath = ""
End If
End function

Private function GetFileName(FullPath)
If FullPath <> "" Then
GetFileName = mid(FullPath,InStrRev(FullPath, "\")+1)
Else
GetFileName = ""
End If
End function

Private function toByte(Str)
dim i,iCode,c,iLow,iHigh
toByte=""
For i=1 To Len(Str)
c=mid(Str,i,1)
iCode =Asc(c)
If iCode<0 Then iCode = iCode + 65535
If iCode>255 Then
iLow = Left(Hex(Asc(c)),2)
iHigh =Right(Hex(Asc(c)),2)
toByte = toByte & chrB("&H"&iLow) & chrB("&H"&iHigh)
Else
toByte = toByte & chrB(AscB(c))
End If
Next
End function
End Class


Class FileInfo
dim FormName,FileName,FilePath,FileSize,FileStart
Private Sub Class_Initialize
FileName = ""
FilePath = ""
FileSize = 0
FileStart= 0
FormName = ""
End Sub

Public function SaveAs(FullPath)
dim dr,ErrorChar,i
SaveAs=1
if trim(fullpath)="" or FileSize=0 or FileStart=0 or FileName="" then exit function
if FileStart=0 or right(fullpath,1)="/" then exit function
set dr=CreateObject("Adodb.Stream")
dr.Mode=3
dr.Type=1
dr.Open
upfile_5xSoft_Stream.position=FileStart-1
upfile_5xSoft_Stream.copyto dr,FileSize
dr.SaveToFile FullPath,2
dr.Close
set dr=nothing
SaveAs=0
end function
End Class
</SCRIPT>
pengdali 2003-10-07
  • 打赏
  • 举报
回复
****************************************************************************
2:upfile.asp
****************************************************************************
<%OPTION EXPLICIT%>
<!--#include FILE="upload_5xsoft.inc"-->
<html>
<head>
<title>文件上传</title>
</head>
<body>
<%
dim upload,file,formName,formPath,iCount

Server.ScriptTimeout=5000

set upload=new upload_5xSoft ''建立上传对象

if upload.form("filepath")="" then ''得到上传目录
HtmEnd "请输入要上传至的目录!"
set upload=nothing
response.end
else
formPath=upload.form("filepath")
''在目录后加(/)
if right(formPath,1)<>"/" then formPath=formPath&"/"
end if

iCount=0
for each formName in upload.file ''列出所有上传了的文件
set file=upload.file(formName) ''生成一个文件对象
if file.FileSize>0 then ''如果 FileSize > 0 说明有文件数据
file.SaveAs Server.mappath(formPath&file.FileName) ''保存文件
response.write file.FilePath&file.FileName&" ("&file.FileSize&") => "&formPath&File.FileName&" 成功!<br>"
iCount=iCount+1
end if
set file=nothing
next
set upload=nothing ''删除此对象
Htmend iCount&" 个文件上传结束!"

sub HtmEnd(Msg)
set upload=nothing
response.write "<br>"&Msg&" [<a href=""javascript:history.back();"">返回</a>] [<a href=list.asp>文件列表</a>]</body></html>"
response.end
end sub
%>
</body>
</html>
****************************************************************************
3:upload_5xsoft.inc
****************************************************************************
<SCRIPT RUNAT=SERVER LANGUAGE=VBSCRIPT>

dim upfile_5xSoft_Stream

Class upload_5xSoft

dim Form,File,Version

Private Sub Class_Initialize
dim iStart,iFileNameStart,iFileNameEnd,iEnd,vbEnter,iFormStart,iFormEnd,theFile
dim strDiv,mFormName,mFormValue,mFileName,mFileSize,mFilePath,iDivLen,mStr
Version="HTTP上传程序 Version 1.0"
if Request.TotalBytes<1 then Exit Sub
set Form=CreateObject("Scripting.Dictionary")
set File=CreateObject("Scripting.Dictionary")
set upfile_5xSoft_Stream=CreateObject("Adodb.Stream")
upfile_5xSoft_Stream.mode=3
upfile_5xSoft_Stream.type=1
upfile_5xSoft_Stream.open
upfile_5xSoft_Stream.write Request.BinaryRead(Request.TotalBytes)

vbEnter=Chr(13)&Chr(10)
iDivLen=inString(1,vbEnter)+1
strDiv=subString(1,iDivLen)
iFormStart=iDivLen
iFormEnd=inString(iformStart,strDiv)-1
while iFormStart < iFormEnd
iStart=inString(iFormStart,"name=""")
iEnd=inString(iStart+6,"""")
mFormName=subString(iStart+6,iEnd-iStart-6)
iFileNameStart=inString(iEnd+1,"filename=""")
if iFileNameStart>0 and iFileNameStart<iFormEnd then
iFileNameEnd=inString(iFileNameStart+10,"""")
mFileName=subString(iFileNameStart+10,iFileNameEnd-iFileNameStart-10)
iStart=inString(iFileNameEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)
if iEnd>iStart then
mFileSize=iEnd-iStart-4
else
mFileSize=0
end if
set theFile=new FileInfo
theFile.FileName=getFileName(mFileName)
theFile.FilePath=getFilePath(mFileName)
theFile.FileSize=mFileSize
theFile.FileStart=iStart+4
theFile.FormName=FormName
file.add mFormName,theFile
else
iStart=inString(iEnd+1,vbEnter&vbEnter)
iEnd=inString(iStart+4,vbEnter&strDiv)

if iEnd>iStart then
mFormValue=subString(iStart+4,iEnd-iStart-4)
else
mFormValue=""
end if
form.Add mFormName,mFormValue
end if

iFormStart=iformEnd+iDivLen
iFormEnd=inString(iformStart,strDiv)-1
wend
End Sub

Private Function subString(theStart,theLen)
dim i,c,stemp
upfile_5xSoft_Stream.Position=theStart-1
stemp=""
for i=1 to theLen
if upfile_5xSoft_Stream.EOS then Exit for
c=ascB(upfile_5xSoft_Stream.Read(1))
If c > 127 Then
if upfile_5xSoft_Stream.EOS then Exit for
stemp=stemp&Chr(AscW(ChrB(AscB(upfile_5xSoft_Stream.Read(1)))&ChrB(c)))
i=i+1
else
stemp=stemp&Chr(c)
End If
Next
subString=stemp
End function

Private Function inString(theStart,varStr)
dim i,j,bt,theLen,str
InString=0
Str=toByte(varStr)
theLen=LenB(Str)
for i=theStart to upfile_5xSoft_Stream.Size-theLen
if i>upfile_5xSoft_Stream.size then exit Function
upfile_5xSoft_Stream.Position=i-1
if AscB(upfile_5xSoft_Stream.Read(1))=AscB(midB(Str,1)) then
InString=i
for j=2 to theLen
if upfile_5xSoft_Stream.EOS then
inString=0
Exit for
end if
if AscB(upfile_5xSoft_Stream.Read(1))<>AscB(MidB(Str,j,1)) then
InString=0
Exit For
end if
next
if InString<>0 then Exit Function
end if
next
End Function
pengdali 2003-10-07
  • 打赏
  • 举报
回复
最好不用存储过程:

==============================================
一共有三个文件,文件名分别是:upfile.html,upfile.asp,upload_5xsoft.inc
文件的源代码分别如下,你只需要将他们粘贴到写字板中,分别存储为上述的文件
名就可以了:
1:upfile.html
******************************************************************8
<html>
<head>
<title>文件上传</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style type="text/css">
<!--
td { font-size: 9pt}
a { color: #000000; text-decoration: none}
a:hover { text-decoration: underline}
.tx { height: 16px; width: 30px; border-color: black black #000000; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 1px; border-left-width: 0px; font-size: 9pt; background-color: #eeeeee; color: #0000FF}
.bt { font-size: 9pt; border-top-width: 0px; border-right-width: 0px; border-bottom-width: 0px; border-left-width: 0px; height: 16px; width: 80px; background-color: #eeeeee; cursor: hand}
.tx1 { height: 20px; width: 30px; font-size: 9pt; border: 1px solid; border-color: black black #000000; color: #0000FF}
-->
</style>
</head>

<body bgcolor="#FFFFFF" text="#000000">
<form name="form1" method="post" action="upfile.asp" enctype="multipart/form-data" >
<table border="1" cellspacing="0" cellpadding="0" bordercolorlight="#000000" bordercolordark="#CCCCCC" width="91" height="23">
<tr>
<td align="left" valign="middle" height="18" width="18"> </td>
<td bgcolor="#CCCCCC" align="left" valign="middle" height="18" width="67"> 文件上传</td>
</tr>
</table>
您的上传目录是:/example/file,一次上传的文件大小不能大于5M,文件上传正在测试中.....
<br>
<input type="hidden" name="act" value="upload">
<br>
<table width="71%" border="1" cellspacing="0" cellpadding="5" align="center" bordercolordark="#CCCCCC" bordercolorlight="#000000">
<tr bgcolor="#CCCCCC">
<td height="22" align="left" valign="middle" bgcolor="#CCCCCC"> 文件上传</td>
</tr>
<tr align="left" valign="middle" bgcolor="#eeeeee">
<td bgcolor="#eeeeee" height="92">
<script language="javascript">
function setid()
{
str='<br>';
if(!window.form1.upcount.value)
window.form1.upcount.value=1;
for(i=1;i<=window.form1.upcount.value;i++)
str+='文件'+i+':<input type="file" name="file'+i+'" style="width:400" class="tx1"><br><br>';
window.upid.innerHTML=str+'<br>';
}
</script>
<li> 需要上传的个数
<input type="text" name="upcount" class="tx" value="1">
<input type="button" name="Button" class="bt" onclick="setid();" value="· 设定 ·">
</li>
<br>
<br>
<li>上传到:
<input type="text" name="filepath" class="tx" style="width:350" value="/example/file">
</li>
</td>
</tr>
<tr align="center" valign="middle">
<td align="left" id="upid" height="122"> 文件1:
<input type="file" name="file1" style="width:400" class="tx1" value="">
</td>
</tr>
<tr align="center" valign="middle" bgcolor="#eeeeee">
<td bgcolor="#eeeeee" height="24">
<input type="submit" name="Submit" value="· 提交 ·" class="bt">
<input type="reset" name="Submit2" value="· 重新执行 ·" class="bt">
</td>
</tr>
</table>
</form>
</body>
</html>
<script language="javascript">

setid();
</script>
txlicenhe 2003-10-07
  • 打赏
  • 举报
回复
用image类型

方法:
1、建立过程
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))
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

2、建表和初始化数据
create table 表名 (编号 int,image列名 image)
go
insert 表名 values(1,0x)
insert 表名 values(2,0x)
go

3、读入
sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\图片.bmp','where 编号=1','I' --注意条件是 编号=1

sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\bb.doc','where 编号=2','I' --注意条件是 编号=2

go

4、读出成文件
sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\图片.bmp','where 编号=1','O' --注意条件是 编号=1

sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\bb.doc','where 编号=2','O' --注意条件是 编号=2
go

如果报textcopy不是可执行文件的话,你就到
C:\Program Files\Microsoft SQL Server\MSSQL\Binn
目录下拷备 textcopy.exe到:
C:\Program Files\Microsoft SQL Server\80\Tools\Binn


*********************************************************************

用Text类型:

READTEXT
UPDATETEXT
WRITETEXT
--------------------
Transact-SQL 参考


READTEXT
读取 text、ntext 或 image 列中的 text、ntext 或 image 值,从指定的偏移量开始读取指定的字节数。

语法
READTEXT { table.column text_ptr offset size } [ HOLDLOCK ]

参数
table.column

是从中读取的表和列的名称。表名和列名必须符合标识符的规则。必须指定表名和列名,不过可以选择是否指定数据库名称和所有者名称。

text_ptr

有效文本指针。text_ptr 必须是 binary(16)。

offset

开始读取 text、image 或 ntext 数据之前跳过的字节数(使用 text 或 image 数据类型时)或字符数(使用 ntext 数据类型时)。使用 ntext 数据类型时,offset 是在开始读取数据前跳过的字符数。使用 text 或 image 数据类型时,offset 是在开始读取数据前跳过的字节数。

size

是要读取数据的字节数(使用 text 或 image 数据类型时)或字符数(使用 ntext 数据类型时)。如果 size 是 0,则表示读取了 4 KB 字节的数据。

HOLDLOCK

使文本值一直锁定到事务结束。其他用户可以读取该值,但是不能对其进行修改。

注释
使用 TEXTPTR 函数获得有效的 text_ptr 值。如果返回不止一行,TEXTPTR 将返回指向指定行中的 text、ntext 或 image 列的指针,或返回指向查询所返回的最后一行中的 text、ntext 或 image 列的指针。由于 TEXTPTR 返回 16 字节的二进制字符串,所以最好声明一个控制文本指针的局部变量,然后在 READTEXT 中使用该变量。有关声明局部变量的更多信息,请参见 DECLARE @local_variable。

在 SQL Server 2000 中可能存在无效的文本指针。有关 text in row 选项的更多信息,请参见 sp_tableoption。有关如何使文本指针无效的更多信息,请参见 sp_invalidate_textptr。

如果 @@TEXTSIZE 函数的值小于为 READTEXT 指定的大小,它将替代为 READTEXT 指定的大小。@@TEXTSIZE 函数是对由 SET TEXTSIZE 语句设置的返回数据字节数的限制。有关如何设置 TEXTSIZE 会话设置的更多信息,请参见 SET TEXTSIZE。

权限
READTEXT 权限默认授予对指定的表具有 SELECT 权限的用户。这些权限可在传递 SELECT 权限时传递。

示例
下例读取 pub_info 表中 pr_info 列的第 2 个至第 26 个字符。

USE pubs
GO
DECLARE @ptrval varbinary(16)
SELECT @ptrval = TEXTPTR(pr_info)
FROM pub_info pr INNER JOIN publishers p
ON pr.pub_id = p.pub_id
AND p.pub_name = 'New Moon Books'
READTEXT pub_info.pr_info @ptrval 1 25
GO


请参见

@@TEXTSIZE

UPDATETEXT

WRITETEXT

©1988-2000 Microsoft Corporation。保留所有权利。
wzhgsww 2003-10-07
  • 打赏
  • 举报
回复
up
hjb111 2003-08-31
  • 打赏
  • 举报
回复
1、建立过程
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))
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

2、建表和初始化数据
create table 表名 (编号 int,image列名 image)
go
insert 表名 values(1,0x)
insert 表名 values(2,0x)
go

3、读入
sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\图片.bmp','where 编号=1','I' --注意条件是 编号=1

sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\bb.doc','where 编号=2','I' --注意条件是 编号=2

go

4、读出成文件
sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\图片.bmp','where 编号=1','O' --注意条件是 编号=1

sp_textcopy '你的服务器名','sa','你的密码','库名','表名','image列名','c:\bb.doc','where 编号=2','O' --注意条件是 编号=2
go
saucer 2003-08-31
  • 打赏
  • 举报
回复
traditionally, people use an upload component or ADODB's AppendChunk or GetChunk, see

http://favorites.myrice.com/eschool/asp/upimage.htm

http://support.microsoft.com/default.aspx?kbid=194975

to use with a sp, you need to use

Set prmData = objCommand.CreateParameter("bytesDados", adLongVarBinary, adParamInput, nFileSize + 1)
objCommand.Parameters.Append prmData
objCommand("bytesDados") = btBytes 'byte data

see how to write such sps at
http://www.eggheadcafe.com/articles/20030624.asp
happydreamer 2003-08-31
  • 打赏
  • 举报
回复
用textcopy对image字段读写

34,590

社区成员

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

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