开发者

What is the easiest way to update an image field with the content of a file

I've a table in MS Sql serve开发者_如何学Pythonr with an image field and a file. What is the easiest way to create a T-Sql script that updates the field with the content of the file?


UPDATE YourTable
SET BlobColumn = 
    (SELECT  BulkColumn FROM OPENROWSET(BULK  N'C:\YourFile.png', SINGLE_BLOB) AS x)
WHERE ...


Drop table employees:

CREATE TABLE Employees
(
    myid int,
    myname varchar(50) not null,
    mypic varbinary(max) not null
)

INSERT INTO Employees (myid, myname, mypic) 
SELECT 10, 'John', BulkColumn 
FROM Openrowset( Bulk 'C:\delete\a.bmp', Single_Blob) as EmployeePicture

UPDATE Employees SET [mypic] =
(
    SELECT MyImage.*
    from Openrowset(Bulk 'C:\Delete\B.bmp', Single_Blob) MyImage)
    where myid = 10

After column i.e. MayImage there should be .* otherwise, it will not work.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜