Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What’s the easiest way to preview data from an image column?

I have some columns with image data type and I want to preview (or browse) the data in those tables. When I use Select top 1000 rows in SQL Server Management Studio, the value of image columns is displayed in hexadecimal. What’s the easiest way to preview those images since the hex-value is not useful to me?

PS.: database is not under my control, so changing data type is not an option.

like image 571
André Avatar asked May 04 '12 19:05

André


People also ask

How do I view images in SQL database?

How to view images stored in your database Start SQL Image Viewer and connect to your database. For SQL Server databases, tables containing blob columns will be highlighted in green in the list of database objects. Write the query to retrieve your images, and execute the query.

What datatype is used for image in SQL Server?

The IMAGE data type in SQL Server has been used to store the image files. Recently, Microsoft began suggesting using VARBINARY(MAX) instead of IMAGE for storing a large amount of data in a single column since IMAGE will be retired in a future version of MS SQL Server.

What is the type of image in database?

To insert images into a database, the database must support images. Images are stored in binary in a table cell. The data type for the cell is a binary large object (BLOB), which is a new SQL type in SQL3 for storing binary data.


1 Answers

If you have LinqPad installed, previewing images is simple. Query your record, convert the binary data to an image, then dump the output to the preview window.

Edit: If you aren't aware, LinqPad is a free utility that can be used for many things, such as a replacement for management studio. Most of the time I use it as a scratch pad for .Net for throw-away programs, test code, and samples.

var entity = // fetch data

using (var ms = new MemoryStream(entity.Image.ToArray()))
{
    System.Drawing.Image.FromStream(ms).Dump();
}

Here's what the result looks like:

enter image description here

like image 132
hawkke Avatar answered Sep 17 '22 23:09

hawkke