Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
CSS
I have a crystal report created in vb.net
I want to display image at runtime using image path stored in sql table.
pls any body help me i need it urgently.
Posted

You must load images to dataset (table) then assign it as a report datasource. Here is an example:
VB
' Function: CreateData
  '       Creates a dataset that has 1 table with two fields: Country (string), and img (blob/byte[])
  '       Adds four records to this table
  '
  Public Function CreateData() As DataSet
      Dim data As New DataSet()

      ' add a table 'Images' to the dataset
      data.Tables.Add("Images")

      ' add two fields
      data.Tables(0).Columns.Add("Country", System.Type.GetType("System.String"))
      data.Tables(0).Columns.Add("img", System.Type.GetType("System.Byte[]"))

      ' create a schema (this schema is used to design the report)
      ' after the report is created, schema file is no longer required
      'data.WriteXmlSchema(Directory.GetCurrentDirectory() & "\DynamicImage.xsd")

      ' add four rows
      AddImageRow(data.Tables(0), "USA", Directory.GetCurrentDirectory() & "\USA.jpg")
      AddImageRow(data.Tables(0), "Canada", Directory.GetCurrentDirectory() & "\Canada.jpg")
      AddImageRow(data.Tables(0), "Germany", Directory.GetCurrentDirectory() & "\Germany.jpg")
      AddImageRow(data.Tables(0), "Japan", Directory.GetCurrentDirectory() & "\Japan.jpg")

      Return (data)
  End Function
  ' Prcocedure: AddImageRow
  '       reads an image file and adds this image to a dataset table
  '
  '   [in]    tbl         DataTable
  '           country     name of a country
  '           filename    name of an image file
  '
  Public Sub AddImageRow(ByRef tbl As DataTable, ByVal country As String, ByVal filename As String)
      Dim fs As New FileStream(filename, FileMode.Open)   ' create a file stream
      Dim br As New BinaryReader(fs)                      ' create binary reader
      Dim row As DataRow

      ' create a new datarow
      row = tbl.NewRow()

      ' set country field and image field
      row(0) = country
      row(1) = br.ReadBytes(br.BaseStream.Length)

      ' add this row to the table
      tbl.Rows.Add(row)

      ' clean up
      br = Nothing
      fs = Nothing
  End Sub
 
Share this answer
 
Comments
Member 9799439 31-Jan-13 3:06am    
Thank you for your help...
But still its not working and can u help me further....?
Raimis9 31-Jan-13 3:34am    
Can you explain, where is a problem, error?
Member 9799439 31-Jan-13 6:04am    
I have written the above code that you provided in Class.So when i run the program it generates a blank report and nothing is displayed.Code is not being executed despite keeping a debug point.
Since i am working in Jewellery line,we have multiple designs added daily which makes it difficult to add rows for every design.So i wanted a solution which will run the code dyanmically without manually editing the code everytime.
The designs should directly be accessed through the folder where the designs are saved.
SQL
str="select distinct code,designname from table1 left join table2 on table1.code=table2.code"
cmd = New SqlCommand(Str, sqlconn)
      adpt = New SqlDataAdapter(cmd)
      DataSetDesign = New DataSet
      DataSetDesign.Clear()
      adpt.Fill(DataSetDesign, "MYtable")


Create a new table "Pic"
Field : DSG_CODE,varchar(15)
        oImg,varbinary(MAX)


        Dim iCtr As Integer
            Dim cPict, cCat, cDesCode, SqlStr As String

            SqlStr = "Delete From pict"

            Dim cmdInsert As SqlCommand
            cmdInsert = New SqlCommand(SqlStr, sqlconn)
            cmdInsert.ExecuteNonQuery()

            For iCtr = 0 To DataSetDesign.Tables(0).Rows.Count - 1
                cCat = Trim(DataSetDesign.Tables(0).Rows(iCtr).Item("designname"))
                cDesCode = Trim(DataSetDesign.Tables(0).Rows(iCtr).Item("code"))

                'Path of Folder
                cPict = "y:\" + cCat + "\DM 3D " + cDesCode + ".JPG"

                    Dim oImg As Byte()
                    oImg = ReadImageFile(cPict)
                    SqlStr = "Insert Into pict(oImg, DSG_Code)values(@oImg , @DSG_Code)"
                    cmdInsert = New SqlCommand(SqlStr, sqlconn)
                    'cmdInsert(Sqlstr, sqlconn)
                    cmdInsert.Parameters.Add("@oImg", Data.SqlDbType.Binary).Value = oImg
                    cmdInsert.Parameters.Add("@DSG_CODE", Data.SqlDbType.VarChar).Value = cDesCode
                    cmdInsert.ExecuteNonQuery()
      Next
 
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