Telerik blogs

There are different ways to store images in a SQL database. In our little demo  we have the images placed as binaries in an image type column in a MS SQL table..

As you may know Silverlight works with a limited range of image formats(PNG and JPG). Therefore I have prepared a small sample database with a few jpeg images inside.

 

Silverlight being a client platform does not have direct access to the SQL server. It needs some server-side code to fetch the data. For the purposes of this demo I have used a WCF service  and Linq To Sql to connect to the database and bring our images to the client. You may find the relevant code in the Service1.cs  file in the sample project below. service1

 

RadGridView for Silverlight has some pretty good support for displaying images .The GridViewImageColumn is part of the magic.

 

We can feed the column directly with the raw bytes from the DB (provided they represent a valid PNG or JPG image).

 

<telerik:GridViewImageColumn DataMemberBinding="{Binding Image.Bytes}" ImageWidth="100" />

 

Having the bytes at the client, the above line is all the code we need to have the images displayed.

 

imagesingrid

For your copy/paste needs please use

 

To see it in action you will need the sample database attached to your SQL server and the Connection string in Web.config set to your local server.


Comments

Comments are disabled in preview mode.