how to add and retrieve a image to and from databse table using open rowset(exaplain)?
is there any other ways of doing image insertion and retrieval?
Thanks and Regards
this post has an example of how to Insert, from disk, a image , both via openrowset and also a vb.net example:http://www.sqlservercentral.com/Forums/FindPost1463248.aspx
If you are going to do something like that regularly, and you feel you have to do it via TSQL and not a programming language/applciaiton, i'd suggest adding some CLR functions to make it much easier; Elliot Witlow has a very nice implementation, with source code, here:
--Elliot Whitlow's project! awesomehttp://nclsqlclrfile.codeplex.com/
and using his project, here 's code examples of reading and writing:
-- Parameters: @FilePath, @FileName
-- purpose: given a path and filename, return the varbinary of the file to store in the database.
CREATE TABLE myImages(id int,filename varchar(200),rawimage varbinary(max) )
INSERT INTO myImages(id,filename,rawimage)
SELECT 1,'fedora_spinner.gif',dbo.MFGetFileImage('C:\Data\','fedora_spinner.gif' )
-- Parameters: @FilePath,@FileName,@FileBytes
-- purpose: given an varbinary image column in a table, write that image to disk
--assumes table and the file from the example above for dbo.MFGetFileImage exists already.
declare @myfile varbinary(max)
SELECT @myfile = rawimage FROM myImages WHERE id = 1
EXEC dbo.MSPSaveFileImage 'C:\Data','spinning.gif',@myfile
--help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!