Click here to Skip to main content
15,742,011 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
I spent three days to pass 3 images using datatable to my report , and always shows broken image icon.

What I have tried:

1- create 3 fields in SQL table with Picture type .
CREATE TABLE [dbo].[Table1](
	[CountryID] [int] NOT NULL,
    [Stamp] [image] NULL,
	[EachPage] [image] NULL,
	[LastPage] [image] NULL,
[CountryID] ASC

2- fill these picture in database, by converting them to array of bytes.
<pre>  If IO.File.Exists(ImagePath) Then
            Dim con As SqlConnection = New SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings.Item("Main").ConnectionString)

                Dim cmd As SqlCommand = New SqlCommand("UPDATE [Table1] set   Stamp  = @Stamp  where CountryID='" & CountryID & "'", con)
         cmd.Parameters.AddWithValue("@Stamp", SqlDbType.Image).Value = ConverttoBinary(ImagePath)

            Catch ex As Exception
                If con.State = ConnectionState.Open Then
                End If
            End Try

        End If

3 - in visual studio , I've been created a Dataset contains a data table with these three fields "the Name is exactly the same".
Dataset screenshot
4- create a blank report , and I added this dataset as report data source .
as shown here in this screenshot :Report
5-Set report datasource the filled dataset .
Public Function Get_DataTable(query As String, DataTableName As String) As PicturesDS
       Dim conString As String = ConfigurationManager.ConnectionStrings("Main").ConnectionString
       Dim cmd As New SqlCommand(query)
       Using con As New SqlConnection(conString)
           Using sda As New SqlDataAdapter()
               cmd.Connection = con

               sda.SelectCommand = cmd
               Using dsEmployees As New PicturesDS()
                   sda.Fill(dsEmployees, DataTableName)
                   Return dsEmployees
               End Using
           End Using
       End Using
   End Function

6-show report.
Private Sub TstImage()

    Dim cryRpt As ReportDocument = New ReportDocument()
    '     cryRpt.Load(Server.MapPath(ReportPath))

    CrystalReportViewer1.ReportSource = cryRpt
    Dim SQLQuery As String = "Select *  FROM [Table1] where CountryID =1 "

    cryRpt.SetDataSource(db.Get_DataTable(SQLQuery, "DTPic"))

End Sub

the result like this :

Broken Image
What I Miss ,
Updated 8-Dec-21 20:07pm
besthms 7-Dec-21 15:00pm    
Thank you for your advice , but this will not fix my issue , am I right ?
Richard Deeming 8-Dec-21 3:57am    
Fixing the security vulnerability will fix the bigger issue of your data being deliberately or accidentally altered or destroyed, or sensitive data being exposed inappropriately leading to a massive fine.
besthms 9-Dec-21 2:41am    
Thank you

1 solution

Ensure you have added Image handler in web.config. Below article has required info.
Display image from database in Crystal Report in ASP.Net using C# and VB.Net[^]
Also check this too
Store and Retrieve Image in Crystal Reports From SQL Database and Folder Using ASP.Net[^]
Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900