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,
CONSTRAINT [PK_Tabl1] PRIMARY KEY CLUSTERED
(
[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)
Try
Dim cmd As SqlCommand = New SqlCommand("UPDATE [Table1] set Stamp = @Stamp where CountryID='" & CountryID & "'", con)
con.Open()
cmd.Parameters.AddWithValue("@Stamp", SqlDbType.Image).Value = ConverttoBinary(ImagePath)
cmd.ExecuteNonQuery()
Catch ex As Exception
Finally
If con.State = ConnectionState.Open Then
con.Close()
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("TstImage.rpt"))
CrystalReportViewer1.ReportSource = cryRpt
Dim SQLQuery As String = "Select * FROM [Table1] where CountryID =1 "
cryRpt.SetDataSource(db.Get_DataTable(SQLQuery, "DTPic"))
GC.Collect()
End Sub
the result like this :
Broken Image
What I Miss ,
I