Wednesday, March 30, 2011

Image Upload and View in SQL Server


Step 1:Create a table like this..

CREATE TABLE [dbo].[image_table](
    [images] [image] NULL
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]


Step 2:
Create a format file like this.

       open a notepad file and type this below after save as .fmt format


---------------------------------------------------------------------------------
8.0
1
1   SQLIMAGE   0   3935      ""      1   picture SQL_Latin1_General_CP1_CI_AS

--------------------------------------------------------------------------------

Step 3: In query analyser  to type the beloy query to upload the image file to database

BULK INSERT image_table FROM 'c:\tmp\Sample.jpg'
WITH (
   FORMATFILE = 'c:\tmp\tam.fmt'
)


Step 4:

If you want to view the image just run the bcp below


bcp ICC_WORLDCUP..image_table out c:\t.jpg -T -N -f tam.fmt

No comments:

Post a Comment