Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Store/Retrieve Images In SQL Table
Message
From
17/02/2010 06:52:27
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01449388
Message ID:
01449405
Views:
52
>>What's involved in storing and retrieving images in a SQL table into a PictureBox on a WinForm?
>
>To answer the question without making a judgement on whether it's a good idea (and I don't neccessarily agree with Michel/Kevin on this):
>
>The image can be stored in a SQL varbinary field. In C# this appears as a byte array (byte[]). You will need to convert this to a BitMap which can then be used as the Image property of the PictureBox. There are several ways of handling the conversion - here's one:
public System.Drawing.Bitmap GetBitMap(byte[] b)
>        {
>            using (System.IO.MemoryStream ms = new System.IO.MemoryStream(b))
>            {
>            return (System.Drawing.Bitmap) System.Drawing.Image.FromStream(ms);
>            }
>        }
>HTH,
>Viv

I would second on that. I too prefer using varbinary if it is 2008 or later.
Starting with SQL2008 there is a FILESTREAM attribute for this purpose. The image (or any binary data) is stored externally on disk and still it is handled by SQL server. To the client it is just any other varbinary(max) column (and can also get direct streaming access if allowed to do so).
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform