How to retrieve binary file from Sql Server database to hard disk using SQL?
-
Hi, I'm Using: SELECT * FROM OPENROWSET(BULK 'G:\1.jpg', SINGLE_BLOB) to save binary files from hard disk to sql server database Now I need an SQL code to retrieve binary file from Sql Server database to hard disk
-
Hi, I'm Using: SELECT * FROM OPENROWSET(BULK 'G:\1.jpg', SINGLE_BLOB) to save binary files from hard disk to sql server database Now I need an SQL code to retrieve binary file from Sql Server database to hard disk
heeeeeeeeey
-
Hi, I'm Using: SELECT * FROM OPENROWSET(BULK 'G:\1.jpg', SINGLE_BLOB) to save binary files from hard disk to sql server database Now I need an SQL code to retrieve binary file from Sql Server database to hard disk
I just SELECT it and use a FileStream to write it. Here's an example:
byte[] content = (byte[]) ds [ 1 ].Rows [ i ] [ "FileContent" ] ;
fs.Write ( content , 0 , content.Length ) ;
fs.Close() ;
ds is a DataSet, and fs is the FileStream.
-
I just SELECT it and use a FileStream to write it. Here's an example:
byte[] content = (byte[]) ds [ 1 ].Rows [ i ] [ "FileContent" ] ;
fs.Write ( content , 0 , content.Length ) ;
fs.Close() ;
ds is a DataSet, and fs is the FileStream.
that is not really streaming anything, so I'd recommend a simple
File.WriteAllBytes()
. BTW: I'm a bit puzzled by theds[**1**]
part... :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
-
that is not really streaming anything, so I'd recommend a simple
File.WriteAllBytes()
. BTW: I'm a bit puzzled by theds[**1**]
part... :)Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.
Luc Pattyn wrote:
File.WriteAllBytes().
In the case I quoted, I had to check whether or not a file by the chosen name existed first. There's no point creating the file if it already exists. So I use a FileInfo to check Exists and simply use its Open method to get a FileStream.
Luc Pattyn wrote:
the ds[1] part
refers to the oneth DataTable in the DataSet -- the set of files I want to create.
-
Luc Pattyn wrote:
File.WriteAllBytes().
In the case I quoted, I had to check whether or not a file by the chosen name existed first. There's no point creating the file if it already exists. So I use a FileInfo to check Exists and simply use its Open method to get a FileStream.
Luc Pattyn wrote:
the ds[1] part
refers to the oneth DataTable in the DataSet -- the set of files I want to create.
:thumbsup:
Luc Pattyn [Forum Guidelines] [Why QA sucks] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, and improve readability.