直接在SQL查询将Image类型的字段转为Base64字符串。

1
2
3
4
DECLARE @img1 VARBINARY ( max ) 
SELECT @img1 = ImageCol FROM xxx WHERE col = '12159'
SELECT *, CAST( '' AS XML ).value( 'xs:base64Binary(sql:variable("@img1"))', 'VARCHAR(MAX)' ) AS img1
FROM xxx WHERE col = '12159'

OR

1
2
3
4
select base64
from xxx
cross apply (select ImageCol as '*' for xml path('')) T (base64)
where col = '12159'

Reference