dbTalk Databases Forums  

Uploading image type using TSQL

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Uploading image type using TSQL in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Artie
 
Posts: n/a

Default Uploading image type using TSQL - 10-26-2007 , 03:12 PM






I have searched for how to upload image data types using just TSQL and
cannot find anything. I do find examples using VBA or ASP but nothing based
on just TSQL. Does anyone know if this is possible.
Using SQL 2000.
Example: I have a Word doc that I want to store in my database. How can I
take a file from the Windows file system such as 'C:\Temp\Mydoc.doc' and
upload it?

CREATE TABLE [DocArchive] (
[DocID] [int] IDENTITY (1, 1) NOT NULL ,
[CreatedDate] [datetime] NOT NULL DEFAULT (getdate()),
[Subject] [varchar] (256) NOT NULL ,
[Category] [char] (30) NULL ,
[SubCategory] [char] (30) NULL ,
[Filename] [varchar] (100)NULL ,
[Document] [image] NULL
)
GO

Thanks.



Reply With Quote
  #2  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: Uploading image type using TSQL - 10-26-2007 , 04:34 PM






Artie (artie2269 (AT) yahoo (DOT) com) writes:
Quote:
I have searched for how to upload image data types using just TSQL and
cannot find anything. I do find examples using VBA or ASP but nothing
based on just TSQL. Does anyone know if this is possible. Using SQL
2000. Example: I have a Word doc that I want to store in my database.
How can I take a file from the Windows file system such as
'C:\Temp\Mydoc.doc' and upload it?

CREATE TABLE [DocArchive] (
[DocID] [int] IDENTITY (1, 1) NOT NULL ,
[CreatedDate] [datetime] NOT NULL DEFAULT (getdate()),
[Subject] [varchar] (256) NOT NULL ,
[Category] [char] (30) NULL ,
[SubCategory] [char] (30) NULL ,
[Filename] [varchar] (100)NULL ,
[Document] [image] NULL
)
GO
SQL Server is a server application, and the idea is that data will come
from clients and be sent to them.

What you can do is to use the BULK INSERT command and load the image
into a one-column table, and the copy the contents to the real table
column.

Keep in mind that the file path is related to the SQL Server
machine. If you run application and SQL Server on the same machine,
this is not an issue, but if you run SQL Server on a separate machine,
and want SQL Server to load a file from your workstation, you will
need to use a UNC path.

Also, keep in mind that if you put this in an application, that the
user must be in the bulkadmin fixed server role to have permission
to run BULK INSERT.


--
Erland Sommarskog, SQL Server MVP, esquel (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.