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

有帮助吗?

解决方案

使用OPENROWSET:

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

已编辑哎呀,您使用的是2000 - 以前的解决方案不受支持。你必须使用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'

其他提示

有一个名为textcopy.exe的工具 您可以在MSSQL \ Binn下找到它或使用SQL Server 2000 SP4

获取它

Alexander Chigrik为SQL查询编写了一个很好的存储过程:

http://www.mssqlcity.com/Articles/KnowHow/Textcopy.htm

本教程中的存储过程对我有用:

有关text,ntext和图片

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top