Using SQL Server 2005 and Management Studio how do I insert a picture into an Image
type column of a table?
Most importantly how do I verify if it is there?
This question is related to
sql
sql-server
sql-server-2005
image
For updating a record:
UPDATE Employees SET [Photo] = (SELECT
MyImage.* from Openrowset(Bulk
'C:\photo.bmp', Single_Blob) MyImage)
where Id = 10
Notes:
Create Table:
Create Table EmployeeProfile (
EmpId int,
EmpName varchar(50) not null,
EmpPhoto varbinary(max) not null )
Go
Insert statement:
Insert EmployeeProfile
(EmpId, EmpName, EmpPhoto)
Select 1001, 'Vadivel', BulkColumn
from Openrowset( Bulk 'C:\Image1.jpg', Single_Blob) as EmployeePicture
This Sql Query Working Fine.
I achieved the goal where I have multiple images to insert in the DB as
INSERT INTO [dbo].[User]
([Name]
,[Image1]
,[Age]
,[Image2]
,[GroupId]
,[GroupName])
VALUES
('Umar'
, (SELECT BulkColumn
FROM Openrowset( Bulk 'path-to-file.jpg', Single_Blob) as Image1)
,26
,(SELECT BulkColumn
FROM Openrowset( Bulk 'path-to-file.jpg', Single_Blob) as Image2)
,'Group123'
,'GroupABC')
For updating a record:
UPDATE Employees SET [Photo] = (SELECT
MyImage.* from Openrowset(Bulk
'C:\photo.bmp', Single_Blob) MyImage)
where Id = 10
Notes:
Create Table:
Create Table EmployeeProfile (
EmpId int,
EmpName varchar(50) not null,
EmpPhoto varbinary(max) not null )
Go
Insert statement:
Insert EmployeeProfile
(EmpId, EmpName, EmpPhoto)
Select 1001, 'Vadivel', BulkColumn
from Openrowset( Bulk 'C:\Image1.jpg', Single_Blob) as EmployeePicture
This Sql Query Working Fine.
I achieved the goal where I have multiple images to insert in the DB as
INSERT INTO [dbo].[User]
([Name]
,[Image1]
,[Age]
,[Image2]
,[GroupId]
,[GroupName])
VALUES
('Umar'
, (SELECT BulkColumn
FROM Openrowset( Bulk 'path-to-file.jpg', Single_Blob) as Image1)
,26
,(SELECT BulkColumn
FROM Openrowset( Bulk 'path-to-file.jpg', Single_Blob) as Image2)
,'Group123'
,'GroupABC')
Source: Stackoverflow.com