image to database please help

thejeraldo

Well-known member
Joined
Jun 9, 2009
Messages
70
Location
Philippines
Programming Experience
1-3
guys i know its easy to to save and fetch images from the database using vb.net. i myself have done this by saving the path of the image. however, i was wondering since this app that im making will have its own database server. so it means that if the database is not located in the client, the path will just end up screwed. any suggestion on how to do this? do i need to use the IMAGE field type on MS SQL? how do i work with it in vb.net? thanks.
 
You definitely don't use the image data type in SQL Server at all. It's deprecated. You'll have to store the images themselves on the server, not just the file paths. For that you should use the varbinary data type. If you're using SQL Server 2008 you can set the FILESTREAM property on the column so that the actual data is stored outside the database itself but managed by SQL Server so you can access it as though it was inside the database.

To store the data in the database you need to convert it to a Byte array first. How you do that exactly depends on where the data is coming from. If it's a local file then you can call File.ReadAllBytes. If it's from an Image object then you can Save it to a MemoryStream first, then get the Byte array from that.
 

Latest posts

Back
Top