有人使用过image的数据类型吗?有个问题想请教各位高手。

myfortunate 2003-05-15 11:15:41
我想在数据中存储图片,.jpg格式的,但是我看见image类型中存放的二进制数,那么如何获得已有图片的二进制码呢?还有怎么样可以将存储的图片取出来?谢谢
...全文
48 点赞 收藏 4
写回复
4 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
pengdali 2003-05-15
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


下面是一个拷贝图像到SQL Server的pubs数据库的例子, 表名pub_info, 字段名logo,图像文件名picture.bmp,保存到pub_id='0736'记录
sp_textcopy @srvname = 'ServerName',
@login = 'Login',
@password = 'Password',
@dbname = 'pubs',
@tbname = 'pub_info',
@colname = 'logo',
@filename = 'c:\picture.bmp',
@whereclause = " WHERE pub_id='0736' ",
@direction = 'I'
回复
happydreamer 2003-05-15
用textcopy存储image

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



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
/* 这是使用textcopy工具将文件插入到数据库中,如果有前台工具可以用前台开发工具将文件插入,这里为了演示 */
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
回复
friendwei 2003-05-15
我就是这样用的
Public Function read_image(read_write As String, ksql As String, source_file_name As String, Optional export_path As String, Optional export_file_name As String, Optional show_photo As PictureBox) As Boolean
On Error GoTo err_msg
dim conn As New Connection
Dim rs As New Recordset
Dim mstream As New Stream
'打开数据库
If kpublic.conn_string = False Then
read_image = False
Exit Function
End If


If db_string <> "" Then
conn.ConnectionTimeout = 39
conn.Open db_string
End If

rs.Open ksql, conn, adOpenKeyset, adLockOptimistic
If read_write = "write" Then
If Dir(source_file_name) = "" Then
kcheck.sys_message "发现所指定的图片文件不存在!!read_image", "waring !!"
read_image = False
End If

'rs.AddNew
mstream.Type = adTypeBinary
mstream.Open
mstream.LoadFromFile source_file_name
rs.Fields(0).Value = mstream.Read

Else

If Dir(export_path, vbDirectory) = "" Then '如输出的路径不存在则新建
MkDir export_path '新增文件夹
End If


mstream.Type = adTypeBinary
mstream.Open
mstream.Write rs.Fields(0).Value
If mstream.Size > 1 Then 'Size >0 表明存放有图片
mstream.SaveToFile export_path & "\" & export_file_name, adSaveCreateOverWrite
If Dir(export_path & "\" & export_file_name) <> "" Then
show_photo.Picture = LoadPicture(export_path & "\" & export_file_name)
End If
End If
End If
rs.Update
rs.Close
conn.Close
read_image = True
Exit Function
err_msg:
kcheck.sys_message "系统在读取图片资料时出现未知错误!!read_image", "waring !!"
read_image = False
End Function
回复
hooboo 2003-05-15
image类型一般是原样放进去,再原样取出来。当然可以改,不过因为image可以存放任何类型的文件,所以修改必须知道结构,有目的的改才有效。为了方便你可以用TEXTCOPY等工具实现存取。当然也可以通过程序来实现(比较麻烦些)
回复
相关推荐
发帖
MS-SQL Server
创建于2007-09-28

3.3w+

社区成员

MS-SQL Server相关内容讨论专区
申请成为版主
帖子事件
创建了帖子
2003-05-15 11:15
社区公告
暂无公告