I want to display image in crystal report from path given in database table.My code runs well but nothing is displayed in report.Below is my code.Please help me to find out the problem.

Dim Con As OdbcConnection = New OdbcConnection
        Dim sql As String = "Select * from Image"
        Con.ConnectionString = connstring
        Dim da As OdbcDataAdapter = New OdbcDataAdapter(sql, Con)
        da.Fill(ds, "Image")
        ds.Tables("Image").Columns.Add("image_stream", Type.GetType("System.Byte[]"))


        For index As Integer = 0 To ds.Tables("Image").Rows.Count - 1
            If ds.Tables("Image").Rows(index)("image_path").ToString <> "" Then
                Dim s As String = ds.Tables("Image").Rows(index)("image_path").ToString
                If File.Exists(s) Then
                    LoadImage(ds.Tables("Image").Rows(index), "image_stream", s)

                End If
            End If
        Next index

        crDoc = New ImageReport
        crDoc.SetDataSource(ds.Tables("Image"))
        rptDoc.ReportSource = crDoc



Private Sub LoadImage(ByVal objDataRow As DataRow, ByVal strImageField As String, ByVal FilePath As String)
        Try
            Dim fs As System.IO.FileStream = New System.IO.FileStream(FilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read)
            Dim Image() As Byte = New Byte(fs.Length) {}
            fs.Read(Image, 0, CType(fs.Length, Integer))
            fs.Close()
            objDataRow(strImageField) = Image
        Catch ex As Exception
            Throw New Exception(ex.Message)
        End Try
    End Sub

First thing is to be sure the crystal report is calling the same dataset as above.

This being said, you are passing the DataRow in as ByVal, you need to pass this in as ByRef.

ByVal only changes the underlying data while in the sub (All changes are lost on sub exit.)

ByRef allows the change of data and the data remains when the sub exists.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.