开发者

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

开发者 https://www.devze.com 2023-01-29 19:56 出处:网络
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

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

精彩评论

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