Add image from db to sql report request

If I create a simple report request to mssql db

if not exists(select * from DeliveryTemplate where TemplateId=2)
    begin 
       select u.usersCode, 1,2,'User {UsersCode}',' hello {Username},', null, dt.DeliveryCode 
       from User u
          left join DeliveryTemplate dt on u.Id = dt.UserId
    end

how can this query be expanded to insert an image from a database where this image is represented as byte [] inside DeliveryTemplate

public class DeliveryTemplate{
   ...
   public virtual byte[] MyImage { get; set; }
}

Just to make it clear I know to convert byte [] to an image , but I don't know how to add an image to the above request.

+4
source share
1 answer

The following T-SQL works for me:

UPDATE DeliveryTemplate SET MyImage = 
(SELECT * FROM OPENROWSET (BULK N'C:\Images\Image.jpg', SINGLE_BLOB) rs) 
WHERE UserId = identity_value

Edit: Create an image field as follows:

ALTER TABLE DeliveryTemplate ADD MyImage VARBINARY(MAX) NULL

, , SQL Server. ( ), SQL Server ( , MSSQL $MSSQLSERVER2012 SQL).

, SQL , MDF ( SSMS Database > Properties > Files). C:\Program Files\Microsoft SQL Server\MSSQL11.MSSQLSERVER2012\MSSQL\DATA.

, , . SQL . MDF LDF !!! ( MDF - " ", MS)

0

Source: https://habr.com/ru/post/1623733/


All Articles