Cómo insertar JPEG en un campo de base de datos SQL Server 2000 de tipo de imagen usando Transact SQL

StackOverflow https://stackoverflow.com/questions/1214462

Pregunta

Estoy tratando de descubrir cómo insertar un archivo .JPG en un campo de base de datos de SQL Server 2000 de tipo imagen usando Transact SQL. Gracias.

¿Fue útil?

Solución

Usar OPENROWSET:

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

EDITADO Vaya, estás usando 2000: la solución anterior no es compatible. Tienes que usar 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'

Otros consejos

Hay una herramienta llamada textcopy.exe Puede encontrarlo en MSSQL \ Binn u obtenerlo con SQL Server 2000 SP4

Alexander Chigrik escribió un buen procedimiento almacenado para usarlo con una consulta SQL:

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

El procedimiento almacenado encontrado en este tutorial funcionó para mí:

Breve tutorial sobre texto, texto y imagen

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top