Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Need to upload images to database - help

Author  Topic 

Mickybee
Starting Member

29 Posts

Posted - 2008-05-30 : 08:14:22
Hia,

We have a simple table which we need to store logo's for a website. The table looks like this:

CLIENTLOGO (Tablename)
id (Bigint) (PK) - NOT NULL
StoredImage (Image) - NOT NULL
ImageSize (Integer) - NULL

Im not an expert on sql sorry!

I have two problems,
1. I need to upload some logo's (they are gif's if thats important)
2. I need to store the image size

I don't have a clue how to do 2 but ive tried the following for 1 but it doesnt seem to work

Insert into CLIENTLOGO (id, storedImageTablename)
Values (1, 'c:\ClientLogo1.gif')

Can somebody help, im really confused about this one


eralper
Yak Posting Veteran

66 Posts

Posted - 2008-05-30 : 08:25:56
Hello MickyBee,

You can try the below script which is using OPENROWSET

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


Insert into EY_EmployeeProfile (EmpId, EmpName, EmpPhoto)
Select 1, 'Eralper',
BulkColumn from Openrowset( Bulk 'C:\avatar.jpg', Single_Blob) as EmployeePicture


Also if you are looking for an ASP.NET application for file upload and storing the image or any file in SQL Server database, you can find a sample with source codes at [url]http://www.kodyaz.com/articles/file-upload-and-save-to-sql-server.aspx[/url]




-------------
Eralper
http://www.kodyaz.com
Go to Top of Page

Mickybee
Starting Member

29 Posts

Posted - 2008-05-30 : 08:51:42
Im not using ASP.NET i simply have new query in sql.

I can't change the datatype from Image to varbinary either.

Ive tried the following but it doesn't work

CLIENTLOGO (Tablename)
id (Bigint) (PK) - NOT NULL
StoredImage (Image) - NOT NULL
ImageSize (Integer) - NULL

Insert into CLIENTLOGO (id, StoredImage)
Select 1, BulkColumn from Openrowset( Bulk 'C:\avatar.jpg', Single_Blob) as StoredImage

Should this work
Go to Top of Page

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2008-05-30 : 09:18:25
Before you spend too much time working that out you should condisder just storing a reference to the filesystem location of the gif file. Then use that reference (path) in the application that will consume this gif.
ie:
Path varchar(n)
filename varchar(n)
filesize int

Be One with the Optimizer
TG
Go to Top of Page

Mickybee
Starting Member

29 Posts

Posted - 2008-05-30 : 09:21:40
Thanks TG.

I know that's what people would normally recommend however there are only 6 images and the techy bods want to store them on the server, not sepaate to the server so I must obey
Go to Top of Page
   

- Advertisement -