Insert image into database

2019-01-27 23:30发布

问题:

I'm trying to insert an image into the database.

CREATE TABLE ImageTable
(
    Id int,
    Name varchar(50) ,
    Photo varbinary(max) 
)

INSERT INTO ImageTable (Id, Name, Photo) 
SELECT 10, 'John', BulkColumn 
FROM Openrowset( Bulk 'C:\caldophilus.jpg', Single_Blob) as EmployeePicture

It throws me an error.

Cannot bulk load. The file "C:\caldophilus.jpg" does not exist.

Please Help.

回答1:

The file is probably on your client PC.
Don't forget that C:\ refers to the server C drive.



回答2:

CREATE TABLE ImageTable
(
    Id int,
    Name varchar(50) ,
    Photo varbinary(max) 
)

INSERT INTO ImageTable (Id, Name, Photo) 
SELECT 10, 'John', BulkColumn 
FROM Openrowset( Bulk 'D:\Test.ico', Single_Blob) as EmployeePicture

Path of the image must be your Server pc where SQl Server are running