Monday, March 19, 2012

How to load images to table

I added a column to a table to hold images. How can I easily upload
these images from the disk file? There are only a few so i thought
there would be a command or utility that I could use, but I haven't
been able to find one.In SQL Server 2005 you can use the BULK option of OPENROWSET:
CREATE TABLE Foo ( image_data VARBINARY(MAX));
INSERT INTO Foo (image_data)
SELECT image_data
FROM OPENROWSET(BULK N'C:\image.jpg',
SINGLE_BLOB) AS ImageSource(image_data);
HTH,
Plamen Ratchev
http://www.SQLStudio.com|||Also take a look at the TEXTCOPY.exe utility. You can Google for TEXTCOPY,
and find a lot of info. But here's one
http://www.mssqlcity.com/Articles/KnowHow/Textcopy.htm
Linchi
"cs_hart@.yahoo.com" wrote:
> I added a column to a table to hold images. How can I easily upload
> these images from the disk file? There are only a few so i thought
> there would be a command or utility that I could use, but I haven't
> been able to find one.
>|||On Jan 22, 2:20 pm, "Plamen Ratchev" <Pla...@.SQLStudio.com> wrote:
> In SQL Server 2005 you can use the BULK option of OPENROWSET:
> CREATE TABLE Foo ( image_data VARBINARY(MAX));
> INSERT INTO Foo (image_data)
> SELECT image_data
> FROM OPENROWSET(BULK N'C:\image.jpg',
> SINGLE_BLOB) AS ImageSource(image_data);
> HTH,
> Plamen Ratchevhttp://www.SQLStudio.com
I tried this but get an error Incorrect syntax near the keyword 'BULK'.|||Are you using SQL Server 2005? As I noted this works only on SQL Server
2005. For uploading images to SQL Server 2000, you can see this example by
Erland Sommarskog:
http://www.sommarskog.se/blobload.txt
HTH,
Plamen Ratchev
http://www.SQLStudio.com

No comments:

Post a Comment