Insert Picture into SQL Server 2005 Image Field Using Only SQL

Insert Picture into SQL Server 2005 Image Field using only SQL


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

How to store image in SQL Server database tables column

give this a try,

insert into tableName (ImageColumn) 
SELECT BulkColumn
FROM Openrowset( Bulk 'image..Path..here', Single_Blob) as img

INSERTING

Sample Image

REFRESHING THE TABLE

Sample Image

How Do You Save An Image Out of a SQL Database Into the File System Using only SQL?

With SQL 2k8 there is the new FILESTREAM type that covers such cases. Filestreams can be opened via the Win32 file access handle like any other file, but hey are integrated into the database from transaction and backup/restore point of view.

I had a similar issue in SQL 2k5 and my solution was to use a CLR stored procedure with EXTERNAL_ACCESS that was writing into the file system using C# file operations.

Insert image taken from a web url into SQL Server

Download Image from a URL using C#

For using WebClient you might need to include the System.Net namespace.

WebClient wc = new WebClient(); 
wc.DownloadFile(URL_Of_The_Image, FileName_You_Want_to_Store_It_As);

Upload an Image into SQL Server table using OPENROWSET

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:\Images\Demo.jpg', Single_Blob) AS EmployeePicture
GO

Refer - http://vadivel.blogspot.in/2005/10/saving-images-as-blob-into-sql-server.html



Related Topics



Leave a reply



Submit