Come inserire JPEG in un campo di database di SQL Server 2000 di tipo immagine usando Transact SQL

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

Domanda

Sto cercando di capire come inserire un file .JPG in un campo del database di SQL Server 2000 di tipo immagine usando Transact SQL. Grazie.

È stato utile?

Soluzione

Usa OPENROWSET:

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

EDITED Whoops, stai usando 2000 - la soluzione precedente non è supportata. Devi usare 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'

Altri suggerimenti

Esiste uno strumento chiamato textcopy.exe Puoi trovarlo in MSSQL \ Binn o scaricarlo con SQL Server 2000 SP4

Alexander Chigrik ha scritto una bella procedura memorizzata per usarla con la query SQL:

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

La procedura memorizzata trovata in questo tutorial ha funzionato per me:

Breve tutorial su testo, ntext e immagine

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top