在ms sql server 安裝目錄下有個(gè)可執(zhí)行文件叫 textcopy.exe 
可對(duì) ms sql server 中的文本或圖像數(shù)據(jù)進(jìn)行輸入輸出. 
不過(guò)你可以在ms-dos方式下執(zhí)行textcopy /? 得到它的描述。 
下面是這個(gè)工具的描述: 
copies a single text or image value into or out of sql server. the val
ue 
is a specified text or image 'column' of a single row (specified by th
e 
"where clause") of the specified 'table'. 
if the direction is in (/i) then the data from the specified 'file' is
copied into sql server, replacing the existing text or image value. if
the 
direction is out (/o) then the text or image value is copied from 
sql server into the specified 'file', replacing any existing file. 
textcopy [/s ][sqlserver]] [/u [login]] [/p ][password]] 
[/d ][database]] [/t table] [/c column] [/w"where clause"] 
[/f file] [{/i | /o}] [/k chunksize] [/z] [/?] 
/s sqlserver the sql server to connect to. if 'sqlserver' is n
ot 
specified, the local sql server is used. 
/u login the login to connect with. if 'login' is not spec
ified, 
a trusted connection will be used. 
/p password the password for 'login'. if 'password' is not 
specified, a null password will be used. 
/d database the database that contains the table with the tex
t or 
image data. if 'database' is not specified, the d
efault 
database of 'login' is used. 
/t table the table that contains the text or image value. 
/c column the text or image column of 'table'. 
/w "where clause" a complete where clause (including the where keyw
ord) 
that specifies a single row of 'table'. 
/f file the file name. 
/i copy text or image value into sql server from 'fi
le'. 
/o copy text or image value out of sql server into '
file'. 
/k chunksize size of the data transfer buffer in bytes. minimu
m 
value is 1024 bytes, default value is 4096 bytes.
/z display debug information while running. 
/? display this usage information and exit. 
you will be prompted for any required options you did not specify.
為此, 可寫一個(gè)存儲(chǔ)過(guò)程,調(diào)用這個(gè)命令 
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 
下面是一個(gè)拷貝圖像到sql server的pubs數(shù)據(jù)庫(kù)的例子, 表名pub_info, 字段名
logo,圖像文件名picture.bmp,保存到pub_id='0736'記錄 sp_textcopy @srvn
ame = 'servername', 
@login = 'login', 
@password = 'password', 
@dbname = 'pubs', 
@tbname = 'pub_info', 
@colname = 'logo', 
@filename = 'c:/picture.bmp', 
@whereclause = " where pub_id='0736' ", 
@direction = 'i' 
新聞熱點(diǎn)
疑難解答
圖片精選