|
-
Oct 29th, 2003, 05:59 AM
#1
Thread Starter
New Member
Retrieve Binary File from SQL Server
Hi,
I want to retrieve a binary file from SQL Server using ADO.NET. How can I accomplish this?
Thanks in advance.
Regards,
N Y Prakash 
-
Oct 29th, 2003, 06:03 PM
#2
Hyperactive Member
These are the steps I used.
1. Create a dataset control from your data tab. Put a table in it with a single image field (really a binary field).
2. Create a connection to your SQL Database with a dataadapter control.
3. Fill the dataset field with the image field from your SQL Database.
4. Use a binary writer to put the contents to a file.
My example below retrieves a JPG from my database and saves it to a file called temp.jpg. It assumes you have a dataset called dsTables with a table called Image and a dataadapter called sdaImage with a table called images and two fields, one called image and one called image_number.
Code:
dsTables.Tables("Image").Clear()
Dim fsImage As New System.IO.FileStream("test.jpg", System.IO.FileMode.Create)
Dim bwImage As New System.IO.BinaryWriter(fsImage)
sdaImage.SelectCommand.CommandText = "select image from images where image_number = '12345' "
Dim nRecords as Int16 ' holds number of records returned by fill
nRecords sdaImage.Fill(dsTables, "Image") 'fill dataset with binary blob
If nRecords > 0 Then
bwImage.Write(dsTables.Tables("Image").Rows(0).Item(0)) 'retrieve binary blob from dataset
End If
bwImage.Flush() 'write binary blob to file specified above
bwImage.Close()
fsImage = Nothing
bwImage = Nothing
Last edited by scuzymoto; Oct 29th, 2003 at 06:16 PM.
SCUZ
-
Oct 30th, 2003, 02:24 PM
#3
Banned
Hi prakash
you use stream object here
in .net we can use the stream object for binary file and alos picture object
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|