如何使用Transact SQL将JPEG插入到图像类型的SQL Server 2000数据库字段中 [英] How to insert JPEG into a SQL Server 2000 database field of image type using Transact SQL

查看:152
本文介绍了如何使用Transact SQL将JPEG插入到图像类型的SQL Server 2000数据库字段中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试弄清楚如何使用Transact SQL将.JPG文件插入到图像类型的SQL Server 2000数据库字段中。谢谢。

I'm trying to figure out how to insert a .JPG file into a SQL Server 2000 database field of type image using Transact SQL. Thanks.

推荐答案

使用OPENROWSET:

Use OPENROWSET:

INSERT MyTable (ImageColumnName) 
SELECT BulkColumn FROM OPENROWSET (BULK 'c:\myjpeg.jpg', SINGLE_BLOB) AS X

已编辑哎呀,您使用的是2000 - 以前的解决方案不受支持。你必须使用WRITETEXT:

EDITED Whoops, you're using 2000--the previous solution is not supported. You have to use WRITETEXT:

CREATE TABLE MyTable 
(
    ID INT PRIMARY KEY IDENTITY (1,1), 
    ImageColumnName IMAGE NULL
)
GO

-- must insert a dummy value into the image column for TEXTPTR 
-- to work in next bit
DECLARE @RowId INT
INSERT MyTable (ImageColumnName) VALUES (0xFFFFFFFF)
SELECT @RowId = SCOPE_IDENTITY()

-- get a pointer value to the row+column you want to 
-- write the image to
DECLARE @Pointer_Value varbinary(16)
SELECT @Pointer_Value = TEXTPTR(ImageColumnName)
FROM MyTable
WHERE Id = @RowId

-- write the image to the row+column pointer
WRITETEXT MyTable.ImageColumnName @Pointer_Value 'c:\myjpeg.jpg'

这篇关于如何使用Transact SQL将JPEG插入到图像类型的SQL Server 2000数据库字段中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆