Download varbinary file in Database

ryoka012

Active member
Joined
Oct 13, 2011
Messages
32
Programming Experience
Beginner
Hi Expert,


How can i accomplish in downloading the converted file to varbinary in Database using VB.net.
I'am lost on how can i accomplish this.

Desperate need your help.

Thanks.
 
Hi Expert,


How can i accomplish in downloading the converted file to varbinary in Database using VB.net.
I'am lost on how can i accomplish this.

Desperate need your help.

Thanks.
You'll need a SqlCommand, SqlDataReader, and FileWriter to do this.
Use the SqlCommand to query the database for the varbinary field, then use the SqlDataReader to retrieve the bytes and write them to a file.
Here's an example doing just that: How to retrieve VARBINARY values from SQL Server 2008 using VB.Net - Stack Overflow
 
Storing files in a database is basically just like storing any other data. You get it into and out of the database in exactly the same way as you do any other data. When using ADO.NET, the data is represented with a Byte array. You can get a Byte array from a file and write a Byte array to a file using the File.ReadAllBytes and File.WriteAllBytes methods. For large files, you may need to stream the data to avoid high memory usage. That complicates things a bit but for most files you can just use a Byte array containing all the data.
 
Back
Top