当前位置:首页 > 软件开发 > dev
firefox

如何把图片、声音等存储到sql中

如何不通过其他工具,把图片、声音等存储到sql中 用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)    -- 必须的,且不是null
insert 表名 values(2,0x)    -- 必须的,且不是null
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

 ↓相关文章:
© 2006-2008 All Rights Reserved