Skip to main content Skip to footer

How to Display SQLite BLOB Images in a .NET Reporting Application

  • 0 Comments
Quick Start Guide
What You Will Need

ActiveReports.NET 

SQLite Database

Controls Referenced

Image Control

Tutorial Concept Learn how to retrieve and display images stored as BLOBs in an SQLite database within a .NET reporting application. This tutorial walks you through extracting, converting, and embedding image data into your reports for a seamless visual presentation.

Displaying images stored as BLOBs in an SQLite database within a .NET reporting application can be challenging without the right approach. Whether you're working with invoices, product catalogs, or other data-driven reports, seamlessly integrating image data enhances report clarity and usability. In this guide, we’ll explore how to retrieve and display SQLite BLOB images in a .NET reporting application, ensuring your reports present visual data effectively. Let’s dive into the steps needed to extract, convert, and embed images into your reports with ease.

We'll go over how to display such images in your .NET reports created with ActiveReports.NET.

Ready to Try it Out? Download ActiveReports.NET Today!

We will use the SQLite Data Provider, which was introduced in ActiveReports.NET 16, to bind to our employees.sqlite database: 

Report Data Source

We'll add a dataset as usual. Please see this page if you're unfamiliar with data binding in ActiveReports.NET. 

At this point, all you must do is set the following properties for the image control:

  • Source: Database
  • Value: =Fields!employeeImage.Value

If, however, you are using a prior version of ActiveReports.NET (v15 or earlier), we need a bit of code to convert the BLOB image from your SQLite database. Here's a sample code:

Public Function BlobToByte(ByVal x) As Byte()
    Dim str As String = BlobToString(x)
    Return System.Text.Encoding.Default.GetBytes(str)    
End Function
 
Public Function BlobToString(ByVal x) As String    
    Dim str As String = HexToString(x.Substring(2, x.Length - 3)) 'remove envelope sqlite 
    Return str.Substring(78, str.Length - 79) ' remove header Bitmap Image Paint.Picture
End Function
 
Function HexToString(ByVal hex As String) As String
    Dim text As New System.Text.StringBuilder(hex.Length \ 2)
    For i As Integer = 0 To hex.Length - 2 Step 2
        text.Append(Chr(Convert.ToByte(hex.Substring(i, 2), 16)))
    Next
    Return text.ToString
End Function

Place this code in the “Script” section of our RDL report:

RDL Report

Select the Image control on the design surface, and change its “Value” Property to:

=code.BlobToByte(Fields!Picture.Value)

This expression tells the RDL report to look in the Script section for a Function named BlobToByte, which takes the BLOB image as a parameter.

Here's how the report looks in the preview:

Report Preview

To see the complete implementation, download the zip file here: SqliteBlob.zip

Integrating SQLite BLOB images into a .NET reporting application enhances the visual appeal and functionality of your reports. By efficiently retrieving and converting image data, you can ensure seamless integration without compromising performance. Whether you're displaying product images, employee photos, or other visual elements, this approach provides a reliable solution for handling embedded images in your reports. With these techniques, you can create more dynamic and informative reports that effectively communicate your data.

Learn more about ActiveReports.NET features by visiting ourOnline Demos.

Ready to Try it Out? Download ActiveReports.NET Today!