views:

12403

answers:

6

Using Ms SQL Server 2005 and Management Studio how do I insert a picture into an Image type field of a table?
Most importantly how do I verify if it is there?

A: 

This might solve your problem.

As to verifying that it's there - you may have to write a small app that takes an id value and then goes and retrieves the image.

Yes, a small app would do the trick, but I am "forced" to do with SQL :)
Germstorm
+11  A: 
CREATE TABLE Employees
(
    Id int,
    Name varchar(50) not null,
    Photo varbinary(max) not null
)


INSERT INTO Employees (Id, Name, Photo) SELECT 10, 'John', BulkColumn from Openrowset( Bulk 'C:\photo.bmp', Single_Blob) as EmployeePicture
Darin Dimitrov
If I had more rep, I would, but could somebody form this answer?
kzh
A: 
Create Table EmployeeProfile

( EmpId int, EmpName varchar(50) not null, EmpPhoto varbinary(max) not null ) Go

Insert EmployeeProfile (EmpId, EmpName, EmpPhoto) Select 1001, 'Vadivel', BulkColumn from Openrowset( Bulk 'C:\Image1.jpg', Single_Blob) as EmployeePicture

This Sql Query Working Fine...........Prasanna Yelsangikar

prasanna.yelsangikar
+2  A: 

For updating a record:

UPDATE Employees SET [Photo] = (SELECT MyImage.* from Openrowset(Bulk 'C:\photo.bmp', Single_Blob) MyImage) where Id = 10

Notes:

  • Make sure to add the 'BULKADMIN' Role Permissions for the login you are using.
  • Paths are not pointing to your computer when using SQL Server Management Studio. If you start SSMS on your local machine and connect to a SQL Server instance on server X, the file C:\photo.bmp will point to hard drive C: on server X, not your machine!
mathijsuitmegen
A: 

this is really really cool man... i can't believe its working.. i was looking for this allover man...thnx a lot man...

this is soooooooooooo simple and i was soo confused abt it all these days..reallly thnx a lot man

ram
A: 

What does that Single_Blob means?

Piyush